Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix live interfaces for audio/image streaming #9883

Merged
merged 6 commits into from
Nov 4, 2024

Conversation

freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Oct 31, 2024

Description

When an interface is live, the events are configured via gr.on and there are some modifications needed for the stream events to be set up correctly if the input components are set to streaming=True.

Also added time_limit and stream_every to the interface class for users to control the stream event behavior.

Closes: #9837
Closes: #9869

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 31, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/39a62ff596773c2aff535add0e24df3562d8f7a7/gradio-5.4.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@39a62ff596773c2aff535add0e24df3562d8f7a7#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/39a62ff596773c2aff535add0e24df3562d8f7a7/gradio-client-1.7.1.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/39a62ff596773c2aff535add0e24df3562d8f7a7/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 31, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/audio patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix live interfaces for audio/image streaming

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

Sorry, something went wrong.

@@ -201,7 +201,7 @@
dispatch("start_recording");
if (!inited) await prepare_audio();
header = undefined;
if (streaming) {
if (streaming && recorder.state != "recording") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes this would get triggered twice and there would be an exception in the console since the recorder was already recording. But it wouldn't break anything.

@freddyaboulton freddyaboulton marked this pull request as ready for review November 1, 2024 00:43
@freddyaboulton freddyaboulton requested review from abidlabs, aliabid94, pngwn, aliabd, dawoodkhan82 and hannahblair and removed request for aliabid94 November 1, 2024 00:44
@@ -679,7 +681,11 @@ async def process_events(
if awake_events[0].streaming:
awake_events, closed_events = await Queue.wait_for_batch(
awake_events,
[cast(float, fn.time_limit) - first_iteration]
# We need to wait for all of the events to have the latest input data
# the max time is the time limit of the function or 90 seconds (arbitrary) but should
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# the max time is the time limit of the function or 90 seconds (arbitrary) but should
# the max time is the time limit of the function or 30 seconds (arbitrary) but should

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

@@ -702,7 +708,9 @@ def attach_submit_events(
preprocess=not (self.api_mode),
postprocess=not (self.api_mode),
show_progress="hidden" if streaming_event else self.show_progress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point unrelated to this PR, but I think we should just make show_progress="hidden" if live=True

[
d["name"]
for d in _event_specific_args
if d.get("component_prop", "true") != "false"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this component_prop attribute mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not to pass this arguments (stream_every or time_limit) it to svelte component in the front-end. Only stream_every is used in the component code. time_limit is used by statustracker.

@abidlabs
Copy link
Member

abidlabs commented Nov 4, 2024

Looks good to me @freddyaboulton! With regards to #9837, can we print a warning if someone uses a streaming input and does not set live=True?

@freddyaboulton freddyaboulton merged commit e10bbd2 into main Nov 4, 2024
22 of 23 checks passed
@freddyaboulton freddyaboulton deleted the fix-live-interfaces branch November 4, 2024 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Streaming ASR Demo doesn't work in v_5.4.0 Gr.Image Streaming Returning None
3 participants