|
1 | 1 | import asyncio |
2 | 2 | import pathlib |
3 | | -from typing import AsyncGenerator, Literal |
| 3 | +from typing import AsyncGenerator, Literal, cast |
4 | 4 |
|
| 5 | +from fastrtc import AsyncStreamHandler, WebRTC, async_aggregate_bytes_to_16bit |
5 | 6 | from google import genai |
6 | 7 | from google.genai.types import ( |
7 | 8 | Content, |
|
12 | 13 | VoiceConfig, |
13 | 14 | ) |
14 | 15 | import gradio as gr |
15 | | -from gradio_webrtc import AsyncStreamHandler, WebRTC, async_aggregate_bytes_to_16bit |
16 | 16 | import numpy as np |
17 | 17 |
|
18 | 18 | current_dir = pathlib.Path(__file__).parent |
@@ -41,7 +41,7 @@ def __init__( |
41 | 41 | def copy(self) -> "GeminiHandler": |
42 | 42 | """Required implementation of the copy method for AsyncStreamHandler""" |
43 | 43 | return GeminiHandler( |
44 | | - expected_layout=self.expected_layout, |
| 44 | + expected_layout=cast(Literal["mono"], self.expected_layout), |
45 | 45 | output_sample_rate=self.output_sample_rate, |
46 | 46 | output_frame_size=self.output_frame_size, |
47 | 47 | ) |
@@ -71,7 +71,13 @@ async def connect( |
71 | 71 | ) |
72 | 72 | ) |
73 | 73 | ), |
74 | | - system_instruction=Content(parts=[Part.from_text(text=system_instruction)]), |
| 74 | + system_instruction=Content( |
| 75 | + parts=[ |
| 76 | + Part.from_text( |
| 77 | + text=system_instruction or "You are a helpful assistant." |
| 78 | + ) |
| 79 | + ] |
| 80 | + ), |
75 | 81 | ) |
76 | 82 | async with client.aio.live.connect( |
77 | 83 | model="gemini-2.0-flash-live-preview-04-09", config=config |
@@ -153,7 +159,7 @@ def shutdown(self) -> None: |
153 | 159 | mode="send-receive", |
154 | 160 | # See for changes needed to deploy behind a firewall |
155 | 161 | # https://fastrtc.org/deployment/ |
156 | | - rtc_configuration=None, |
| 162 | + rtc_configuration={}, |
157 | 163 | ) |
158 | 164 |
|
159 | 165 | webrtc.stream( |
|
0 commit comments