mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
6e6121a1ac
* placeholder * changelog * added to readme * client * implement futures * utils * scripts * lint * reorg * scripts * serialization * cleanup * fns * serialize * cache * callbacks * updates * formatting * packaging * requirements * remove changelog * client * access token * formatting * deprecate * format backend * client replace * updates * moving from utils * remove code duplication * rm duplicates * simplify * galleryserializer * serializable * load serializers * fixing errors * errors * typing * tests * changelog * lint * fix lint * fixing files * formatting * type * fix type checking * changelog * changelog * Update client/python/gradio_client/client.py Co-authored-by: Lucain <lucainp@gmail.com> * formatting, tests * formatting, tests * gr.load * refactoring * refactoring' * formatting * formatting * tests * tests * fix tests * cleanup * added tests * adding scripts * formatting * address review comments * readme * serialize info * remove from changelog * version 0.0.2 released * lint * type fix * check * type issues * hf_token * update hf token * telemetry * docs, circle dependency * hf token * formatting * updates * sort * script * external * docs * formatting * fixes * scripts * requirements * fix tests * context * changes * formatting * fixes * format fix --------- Co-authored-by: Lucain <lucainp@gmail.com>
67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
import json
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import gradio as gr
|
|
from gradio import mix
|
|
from gradio.external import TooManyRequestsError
|
|
|
|
"""
|
|
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.
|
|
"""
|
|
|
|
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
|
|
|
|
|
class TestSeries:
|
|
def test_in_interface(self):
|
|
io1 = gr.Interface(lambda x: x + " World", "textbox", gr.Textbox())
|
|
io2 = gr.Interface(lambda x: x + "!", "textbox", gr.Textbox())
|
|
series = mix.Series(io1, io2)
|
|
assert series("Hello") == "Hello World!"
|
|
|
|
@pytest.mark.flaky
|
|
def test_with_external(self):
|
|
io1 = gr.load("spaces/abidlabs/image-identity")
|
|
io2 = gr.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
|
|
|
|
|
|
class TestParallel:
|
|
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())
|
|
parallel = mix.Parallel(io1, io2)
|
|
assert parallel("Hello") == ["Hello World 1!", "Hello World 2!"]
|
|
|
|
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)
|
|
assert parallel("Hello") == [
|
|
"Hello",
|
|
"HelloHello",
|
|
"Hello World 2!",
|
|
]
|
|
|
|
@pytest.mark.flaky
|
|
def test_with_external(self):
|
|
io1 = gr.load("spaces/abidlabs/english_to_spanish")
|
|
io2 = gr.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
|