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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable streaming audio in python client #5248
Changes from all commits
120a7fd
509dda6
ebfbfae
8783d98
7879a0d
3c0ee45
51329b8
5e5f4eb
416f818
0337b8f
cc1f16c
48cc495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
"gradio": minor | ||
"gradio_client": minor | ||
--- | ||
|
||
highlight: | ||
|
||
#### Enable streaming audio in python client | ||
|
||
The `gradio_client` now supports streaming file outputs 馃寠 | ||
|
||
No new syntax! Connect to a gradio demo that supports streaming file outputs and call `predict` or `submit` as you normally would. | ||
|
||
```python | ||
import gradio_client as grc | ||
client = grc.Client("gradio/stream_audio_out") | ||
|
||
# Get the entire generated audio as a local file | ||
client.predict("/Users/freddy/Pictures/bark_demo.mp4", api_name="/predict") | ||
|
||
job = client.submit("/Users/freddy/Pictures/bark_demo.mp4", api_name="/predict") | ||
|
||
# Get the entire generated audio as a local file | ||
job.result() | ||
|
||
# Each individual chunk | ||
job.outputs() | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pytest==7.1.2 | |
ruff==0.0.264 | ||
pyright==1.1.305 | ||
gradio | ||
pydub==0.25.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1360,10 +1360,10 @@ def handle_streaming_outputs( | |
if run not in self.pending_streams[session_hash]: | ||
self.pending_streams[session_hash][run] = defaultdict(list) | ||
self.pending_streams[session_hash][run][output_id].append(stream) | ||
data[i] = { | ||
"name": f"{session_hash}/{run}/{output_id}", | ||
"is_stream": True, | ||
} | ||
if data[i]: | ||
data[i]["is_file"] = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But isn't ["name"] assigned to the same value as before in the next line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea we're using "name" to mean the url from which to download the stream so I'm keeping that the same. Just preserving |
||
data[i]["name"] = f"{session_hash}/{run}/{output_id}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aliabid94 Thoughts on including the |
||
data[i]["is_stream"] = True | ||
return data | ||
|
||
async def process_api( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly that what's happening is that we are iterating chunk by chunk and then finally yielding the full array so that
.predict()
returns the full data array? 2 questions:(1) How come outputs() doesn't include this final full data array?
(2) Will
r.iter_bytes()
work if the streaming response returns binary data (as in #5238) instead of file data?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) outputs only includes the values returned from the server during the
process_generating
event(2) yea the
stream
enpoint only serves bytes so it should work when #5238 is merged