Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -158,13 +158,15 @@ class GeminiInteractionLoop:
|
|
158 |
self.is_running = True
|
159 |
self.playback_stream = None
|
160 |
|
161 |
-
async def send_text_input_to_gemini(self):
|
162 |
if not user_text or not self.gemini_session or not self.is_running:
|
163 |
logging.warning(
|
164 |
"Cannot send text. Session not active, no text, or not running.")
|
165 |
return
|
166 |
try:
|
167 |
-
|
|
|
|
|
168 |
except Exception as e:
|
169 |
logging.error(
|
170 |
f"Error sending text message to Gemini: {e}", exc_info=True)
|
@@ -431,7 +433,8 @@ class GeminiInteractionLoop:
|
|
431 |
f"Gemini session established with API for model {MODEL_NAME}.")
|
432 |
try:
|
433 |
logging.info("Sending system prompt to Gemini...")
|
434 |
-
|
|
|
435 |
logging.info("System prompt sent successfully.")
|
436 |
except Exception as e:
|
437 |
logging.error(
|
@@ -468,8 +471,7 @@ class GeminiInteractionLoop:
|
|
468 |
task.cancel()
|
469 |
# Await their cancellation (or completion if they finished cleanly before cancel)
|
470 |
if tasks: # Ensure tasks list is not empty
|
471 |
-
await asyncio.gather(*tasks, return_exceptions
|
472 |
-
=True) # Suppress errors from already handled/cancelled tasks
|
473 |
logging.info("Gemini interaction tasks processing completed or handled.")
|
474 |
|
475 |
except websockets.exceptions.ConnectionClosedError as e:
|
@@ -707,4 +709,4 @@ if __name__ == "__main__":
|
|
707 |
if client is None:
|
708 |
logging.critical("Gemini client could not be initialized. Application cannot start.")
|
709 |
else:
|
710 |
-
run_streamlit_app()
|
|
|
158 |
self.is_running = True
|
159 |
self.playback_stream = None
|
160 |
|
161 |
+
async def send_text_input_to_gemini(self, user_text):
|
162 |
if not user_text or not self.gemini_session or not self.is_running:
|
163 |
logging.warning(
|
164 |
"Cannot send text. Session not active, no text, or not running.")
|
165 |
return
|
166 |
try:
|
167 |
+
logging.info(f"Sending text to Gemini: '{user_text[:50]}...'")
|
168 |
+
# Send text directly using the send method
|
169 |
+
await self.gemini_session.send(input={"text": user_text})
|
170 |
except Exception as e:
|
171 |
logging.error(
|
172 |
f"Error sending text message to Gemini: {e}", exc_info=True)
|
|
|
433 |
f"Gemini session established with API for model {MODEL_NAME}.")
|
434 |
try:
|
435 |
logging.info("Sending system prompt to Gemini...")
|
436 |
+
# Send system prompt using the correct format
|
437 |
+
await self.gemini_session.send(input={"text": MEDICAL_ASSISTANT_SYSTEM_PROMPT})
|
438 |
logging.info("System prompt sent successfully.")
|
439 |
except Exception as e:
|
440 |
logging.error(
|
|
|
471 |
task.cancel()
|
472 |
# Await their cancellation (or completion if they finished cleanly before cancel)
|
473 |
if tasks: # Ensure tasks list is not empty
|
474 |
+
await asyncio.gather(*tasks, return_exceptions=True) # Suppress errors from already handled/cancelled tasks
|
|
|
475 |
logging.info("Gemini interaction tasks processing completed or handled.")
|
476 |
|
477 |
except websockets.exceptions.ConnectionClosedError as e:
|
|
|
709 |
if client is None:
|
710 |
logging.critical("Gemini client could not be initialized. Application cannot start.")
|
711 |
else:
|
712 |
+
run_streamlit_app()
|