Skip to content

Commit

Permalink
fix client flaky tests (#8481)
Browse files Browse the repository at this point in the history
* fix client flaky tests

* format

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot authored Jun 6, 2024
1 parent 925a723 commit 41a4493
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .changeset/crazy-turtles-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gradio": minor
"gradio_client": minor
---

feat:fix client flaky tests
2 changes: 1 addition & 1 deletion client/python/gradio_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ def reduce_singleton_output(self, *data) -> Any:
else:
return data

def _upload_file(self, f: str | dict, data_index: int) -> dict[str, str]:
def _upload_file(self, f: dict, data_index: int) -> dict[str, str]:
file_path = f["path"]
orig_name = Path(file_path)
if not utils.is_http_url_like(file_path):
Expand Down
33 changes: 19 additions & 14 deletions client/python/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,25 @@ def test_space_with_files_v4_sse_v2(self):
space_id = "gradio-tests/space_with_files_v4_sse_v2"
client = Client(space_id)
payload = (
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
handle_file(
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
),
{
"video": "https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4",
"video": handle_file(
"https://github.com/gradio-app/gradio/raw/main/demo/video_component/files/world.mp4"
),
"subtitle": None,
},
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
handle_file(
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
),
)
output = client.predict(*payload, api_name="/predict")
assert output[0].endswith(".wav") # Audio files are converted to wav
assert output[1]["video"].endswith(
"world.mp4"
) # Video files are not converted by default
assert (
output[2]
== "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
) # textbox string should remain exactly the same
assert "sample-0.mp3" in output[2]

def test_state(self, increment_demo):
with connect(increment_demo) as client:
Expand Down Expand Up @@ -890,8 +893,8 @@ def test_numerical_to_label_space(self):
"label": "output",
"type": {"type": {}, "description": "any valid json"},
"python_type": {
"type": "str",
"description": "filepath to JSON file",
"type": "Dict[Any, Any]",
"description": "any valid json",
},
"component": "Label",
"serializer": "JSONSerializable",
Expand Down Expand Up @@ -930,8 +933,8 @@ def test_numerical_to_label_space(self):
"label": "output",
"type": {"type": {}, "description": "any valid json"},
"python_type": {
"type": "str",
"description": "filepath to JSON file",
"type": "Dict[Any, Any]",
"description": "any valid json",
},
"component": "Label",
"serializer": "JSONSerializable",
Expand Down Expand Up @@ -970,8 +973,8 @@ def test_numerical_to_label_space(self):
"label": "output",
"type": {"type": {}, "description": "any valid json"},
"python_type": {
"type": "str",
"description": "filepath to JSON file",
"type": "Dict[Any, Any]",
"description": "any valid json",
},
"component": "Label",
"serializer": "JSONSerializable",
Expand Down Expand Up @@ -1266,7 +1269,9 @@ def test_download_private_file(self, gradio_temp_dir):
client = Client(
src="gradio/zip_files",
)
url_path = "https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
url_path = handle_file(
"https://gradio-tests-not-actually-private-spacev4-sse.hf.space/file=lion.jpg"
)
file = client.endpoints[0]._upload_file(url_path, 0) # type: ignore
assert file["path"].endswith(".jpg")

Expand Down
17 changes: 0 additions & 17 deletions test/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ def test_text_to_speech(self):
assert isinstance(interface.input_components[0], gr.Textbox)
assert isinstance(interface.output_components[0], gr.Audio)

def test_text_to_image(self):
model_type = "text-to-image"
interface = gr.load(
"models/osanseviero/BigGAN-deep-128", hf_token=None, alias=model_type
)
assert interface.__name__ == model_type
assert isinstance(interface.input_components[0], gr.Textbox)
assert isinstance(interface.output_components[0], gr.Image)

def test_english_to_spanish(self):
with pytest.raises(GradioVersionIncompatibleError):
gr.load("spaces/gradio-tests/english_to_spanish", title="hi")
Expand Down Expand Up @@ -285,14 +276,6 @@ def test_speech_recognition_model(self):
finally:
io.close()

def test_text_to_image_model(self):
io = gr.load("models/osanseviero/BigGAN-deep-128")
try:
filename = io("chest")
assert filename.lower().endswith((".jpg", ".jpeg", ".png"))
except TooManyRequestsError:
pass

def test_private_space(self):
io = gr.load(
"spaces/gradio-tests/not-actually-private-spacev4-sse", hf_token=HF_TOKEN
Expand Down

0 comments on commit 41a4493

Please sign in to comment.