gradio/test/test_mix.py

67 lines
2.2 KiB
Python
Raw Normal View History

Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
import json
import os
import pytest
2021-05-21 03:16:16 +08:00
import gradio as gr
from gradio import mix
from gradio.external import TooManyRequestsError
2021-11-15 22:39:06 +08:00
"""
WARNING: Some of these tests have an external dependency: namely that Hugging Face's Hub and Space APIs do not change, and they keep their most famous models up.
So if, e.g. Spaces is down, then these test will not pass.
2021-11-15 22:39:06 +08:00
"""
2021-11-10 02:30:59 +08:00
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
2021-05-21 03:16:16 +08:00
class TestSeries:
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
def test_in_interface(self):
io1 = gr.Interface(lambda x: x + " World", "textbox", gr.Textbox())
io2 = gr.Interface(lambda x: x + "!", "textbox", gr.Textbox())
2021-05-21 03:16:16 +08:00
series = mix.Series(io1, io2)
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
assert series("Hello") == "Hello World!"
2021-05-21 03:16:16 +08:00
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
@pytest.mark.flaky
def test_with_external(self):
io1 = gr.Interface.load("spaces/abidlabs/image-identity")
io2 = gr.Interface.load("spaces/abidlabs/image-classifier")
series = mix.Series(io1, io2)
try:
output = series("gradio/test_data/lion.jpg")
assert json.load(open(output))["label"] == "lion"
except TooManyRequestsError:
pass
2021-11-15 22:39:06 +08:00
class TestParallel:
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
def test_in_interface(self):
io1 = gr.Interface(lambda x: x + " World 1!", "textbox", gr.Textbox())
io2 = gr.Interface(lambda x: x + " World 2!", "textbox", gr.Textbox())
2021-05-21 03:16:16 +08:00
parallel = mix.Parallel(io1, io2)
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
assert parallel("Hello") == ["Hello World 1!", "Hello World 2!"]
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
def test_multiple_return_in_interface(self):
io1 = gr.Interface(
lambda x: (x, x + x), "textbox", [gr.Textbox(), gr.Textbox()]
)
io2 = gr.Interface(lambda x: x + " World 2!", "textbox", gr.Textbox())
parallel = mix.Parallel(io1, io2)
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
assert parallel("Hello") == [
"Hello",
"HelloHello",
"Hello World 2!",
]
@pytest.mark.flaky
2022-03-26 03:16:49 +08:00
def test_with_external(self):
io1 = gr.Interface.load("spaces/abidlabs/english_to_spanish")
io2 = gr.Interface.load("spaces/abidlabs/english2german")
parallel = mix.Parallel(io1, io2)
try:
hello_es, hello_de = parallel("Hello")
assert "hola" in hello_es.lower()
assert "hallo" in hello_de.lower()
except TooManyRequestsError:
pass