Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,13 +58,14 @@ async def ws_stream():
|
|
| 58 |
while True:
|
| 59 |
data = await websocket.receive()
|
| 60 |
if isinstance(data, bytes):
|
| 61 |
-
#
|
| 62 |
await session.send(
|
| 63 |
input={"data": data, "mime_type": "audio/pcm;rate=16000"}
|
| 64 |
)
|
| 65 |
elif isinstance(data, str):
|
| 66 |
-
#
|
| 67 |
-
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
print(f"Client -> Gemini Error: {e}")
|
| 70 |
|
|
@@ -79,8 +80,8 @@ async def ws_stream():
|
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Gemini -> Client Error: {e}")
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
await asyncio.gather(client_to_gemini(), gemini_to_client())
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
print(f"Connection failed: {e}")
|
|
|
|
| 58 |
while True:
|
| 59 |
data = await websocket.receive()
|
| 60 |
if isinstance(data, bytes):
|
| 61 |
+
# Send real-time audio input
|
| 62 |
await session.send(
|
| 63 |
input={"data": data, "mime_type": "audio/pcm;rate=16000"}
|
| 64 |
)
|
| 65 |
elif isinstance(data, str):
|
| 66 |
+
# NEW: Explicitly send text as a message turn to trigger response
|
| 67 |
+
# This satisfies the new SDK requirements and avoids the deprecation warning
|
| 68 |
+
await session.send(input=data, end_of_turn=True)
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Client -> Gemini Error: {e}")
|
| 71 |
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
print(f"Gemini -> Client Error: {e}")
|
| 82 |
|
| 83 |
+
# Using gather with return_exceptions to keep tasks alive
|
| 84 |
+
await asyncio.gather(client_to_gemini(), gemini_to_client(), return_exceptions=True)
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
print(f"Connection failed: {e}")
|