From 8f6626cd0e5a0c24e1966fbc3e28185c18a04b61 Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Fri, 11 Oct 2024 13:19:09 -0700 Subject: [PATCH] Fix streaming Audio/Video Output (#9656) * Fix * add changeset * lint * add changeset * type ignore --------- Co-authored-by: gradio-pr-bot Co-authored-by: Abubakar Abid --- .changeset/silly-hairs-burn.md | 5 +++++ gradio/blocks.py | 4 +--- gradio/chat_interface.py | 2 +- gradio/components/audio.py | 1 + gradio/components/video.py | 1 + gradio/routes.py | 4 +--- 6 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .changeset/silly-hairs-burn.md diff --git a/.changeset/silly-hairs-burn.md b/.changeset/silly-hairs-burn.md new file mode 100644 index 000000000000..e9caa11d1fb0 --- /dev/null +++ b/.changeset/silly-hairs-burn.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +feat:Fix streaming Audio/Video Output diff --git a/gradio/blocks.py b/gradio/blocks.py index 2ef83147c5ac..d08bdfc574f3 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -391,9 +391,7 @@ def serve_static_file( return client_utils.synchronize_async( processing_utils.async_move_files_to_cache, data, self ) - except ( - AttributeError - ): # Can be raised if this function is called before the Block is fully initialized. + except AttributeError: # Can be raised if this function is called before the Block is fully initialized. return data diff --git a/gradio/chat_interface.py b/gradio/chat_interface.py index 821a0db2e894..b2611ac1f34e 100644 --- a/gradio/chat_interface.py +++ b/gradio/chat_interface.py @@ -466,7 +466,7 @@ def _setup_stop_events( None, None, None, - cancels=events_to_cancel, + cancels=events_to_cancel, # type: ignore show_api=False, ) diff --git a/gradio/components/audio.py b/gradio/components/audio.py index 71bb76fa10ae..ff9d5f252ca4 100644 --- a/gradio/components/audio.py +++ b/gradio/components/audio.py @@ -339,6 +339,7 @@ async def stream_output( "path": output_id, "is_stream": True, "orig_name": "audio-stream.mp3", + "meta": {"_type": "gradio.FileData"}, } if value is None: return None, output_file diff --git a/gradio/components/video.py b/gradio/components/video.py index 0a2c90c4fdcd..4481c88258ab 100644 --- a/gradio/components/video.py +++ b/gradio/components/video.py @@ -559,6 +559,7 @@ async def stream_output( # Need to set orig_name so that downloaded file has correct # extension "orig_name": "video-stream.mp4", + "meta": {"_type": "gradio.FileData"}, } } if value is None: diff --git a/gradio/routes.py b/gradio/routes.py index 26a097464459..77a839ee8adf 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -461,9 +461,7 @@ def login(form_data: OAuth2PasswordRequestForm = Depends()): not callable(app.auth) and username in app.auth and compare_passwords_securely(password, app.auth[username]) # type: ignore - ) or ( - callable(app.auth) and app.auth.__call__(username, password) - ): # type: ignore + ) or (callable(app.auth) and app.auth.__call__(username, password)): # type: ignore token = secrets.token_urlsafe(16) app.tokens[token] = username response = JSONResponse(content={"success": True})