Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,7 @@ async def process_api(
session_hash=session_hash,
run=run,
root_path=root_path,
final=not is_generating,
)
data = self.handle_streaming_diffs(
block_fn,
Expand Down
2 changes: 2 additions & 0 deletions gradio/route_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,15 @@ def __init__(self):
self.ended = False
self.segment_index = 0
self.playlist = "#EXTM3U\n#EXT-X-PLAYLIST-TYPE:EVENT\n#EXT-X-TARGETDURATION:10\n#EXT-X-VERSION:4\n#EXT-X-MEDIA-SEQUENCE:0\n"
self.max_length = 5
Copy link
Member

Choose a reason for hiding this comment

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

Why do we hardcode a max length here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It can't be undefined in the http spec but this will be overwritten as soon as we start receiving data

Copy link
Member

Choose a reason for hiding this comment

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

Interesting


async def add_segment(self, data: MediaStreamChunk | None):
if not data:
return

segment_id = str(uuid.uuid4())
self.segments.append({"id": segment_id, **data})
self.max_duration = max(self.max_length, data["duration"]) + 1

def end_stream(self):
self.ended = True
2 changes: 1 addition & 1 deletion gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ async def _(session_hash: str, run: int, component_id: int):
if not stream:
return Response(status_code=404)

playlist = "#EXTM3U\n#EXT-X-PLAYLIST-TYPE:EVENT\n#EXT-X-TARGETDURATION:3\n#EXT-X-VERSION:4\n#EXT-X-MEDIA-SEQUENCE:0\n"
playlist = f"#EXTM3U\n#EXT-X-PLAYLIST-TYPE:EVENT\n#EXT-X-TARGETDURATION:{stream.max_duration}\n#EXT-X-VERSION:4\n#EXT-X-MEDIA-SEQUENCE:0\n"

for segment in stream.segments:
playlist += f"#EXTINF:{segment['duration']:.3f},\n"
Expand Down