Spaces:
Running
Running
fix: switch to gemini-2.5 stable & improve audio generation
Browse files- src/agent/llm.py +1 -3
- src/audio/audio_generator.py +2 -6
- src/game_constructor.py +2 -0
- src/main.py +5 -2
src/agent/llm.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
"""Utility functions for working with the language model."""
|
| 2 |
|
| 3 |
-
import asyncio
|
| 4 |
import logging
|
| 5 |
|
| 6 |
-
from google.api_core.exceptions import DeadlineExceeded
|
| 7 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 8 |
|
| 9 |
from config import settings
|
|
@@ -12,7 +10,7 @@ from services.google import ApiKeyPool
|
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
_pool = ApiKeyPool()
|
| 15 |
-
MODEL_NAME = "gemini-2.5-flash
|
| 16 |
|
| 17 |
|
| 18 |
def _get_api_key() -> str:
|
|
|
|
| 1 |
"""Utility functions for working with the language model."""
|
| 2 |
|
|
|
|
| 3 |
import logging
|
| 4 |
|
|
|
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
|
| 7 |
from config import settings
|
|
|
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
_pool = ApiKeyPool()
|
| 13 |
+
MODEL_NAME = "gemini-2.5-flash"
|
| 14 |
|
| 15 |
|
| 16 |
def _get_api_key() -> str:
|
src/audio/audio_generator.py
CHANGED
|
@@ -98,21 +98,17 @@ async def cleanup_music_session(user_hash: str):
|
|
| 98 |
del sessions[user_hash]
|
| 99 |
|
| 100 |
|
| 101 |
-
async def update_audio(user_hash: str,
|
| 102 |
"""
|
| 103 |
Continuously stream audio from the queue as WAV bytes, and clean up
|
| 104 |
when the user disconnects.
|
| 105 |
"""
|
| 106 |
-
if user_hash == "":
|
| 107 |
return
|
| 108 |
|
| 109 |
logger.info(f"Starting audio update loop for user hash: {user_hash}")
|
| 110 |
try:
|
| 111 |
while True:
|
| 112 |
-
if await request.request.is_disconnected():
|
| 113 |
-
logger.info(f"Client disconnected for user hash {user_hash}.")
|
| 114 |
-
break
|
| 115 |
-
|
| 116 |
if user_hash not in sessions:
|
| 117 |
await asyncio.sleep(0.5)
|
| 118 |
continue
|
|
|
|
| 98 |
del sessions[user_hash]
|
| 99 |
|
| 100 |
|
| 101 |
+
async def update_audio(user_hash: str, game_started: bool):
|
| 102 |
"""
|
| 103 |
Continuously stream audio from the queue as WAV bytes, and clean up
|
| 104 |
when the user disconnects.
|
| 105 |
"""
|
| 106 |
+
if user_hash == "" or not game_started:
|
| 107 |
return
|
| 108 |
|
| 109 |
logger.info(f"Starting audio update loop for user hash: {user_hash}")
|
| 110 |
try:
|
| 111 |
while True:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
if user_hash not in sessions:
|
| 113 |
await asyncio.sleep(0.5)
|
| 114 |
continue
|
src/game_constructor.py
CHANGED
|
@@ -144,6 +144,7 @@ async def start_game_with_settings(
|
|
| 144 |
gr.update(),
|
| 145 |
gr.update(), # game components unchanged
|
| 146 |
gr.update(), # custom choice
|
|
|
|
| 147 |
)
|
| 148 |
|
| 149 |
character = Character(
|
|
@@ -183,4 +184,5 @@ async def start_game_with_settings(
|
|
| 183 |
gr.update(value=scene_image), # game_image
|
| 184 |
gr.update(choices=scene_choices, value=None), # game_choices
|
| 185 |
gr.update(value="", visible=True), # custom choice
|
|
|
|
| 186 |
)
|
|
|
|
| 144 |
gr.update(),
|
| 145 |
gr.update(), # game components unchanged
|
| 146 |
gr.update(), # custom choice
|
| 147 |
+
gr.update(),
|
| 148 |
)
|
| 149 |
|
| 150 |
character = Character(
|
|
|
|
| 184 |
gr.update(value=scene_image), # game_image
|
| 185 |
gr.update(choices=scene_choices, value=None), # game_choices
|
| 186 |
gr.update(value="", visible=True), # custom choice
|
| 187 |
+
gr.update(value=True), # game_started
|
| 188 |
)
|
src/main.py
CHANGED
|
@@ -118,6 +118,7 @@ async def start_game_with_music(
|
|
| 118 |
gr.update(),
|
| 119 |
gr.update(), # game components unchanged
|
| 120 |
gr.update(), # custom choice unchanged
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
# First, get the game interface updates
|
|
@@ -143,6 +144,7 @@ with gr.Blocks(
|
|
| 143 |
gr.HTML("<div class='loading-text'>🚀 Starting your adventure...</div>")
|
| 144 |
|
| 145 |
ls_user_hash = gr.BrowserState("", "user_hash")
|
|
|
|
| 146 |
|
| 147 |
# Constructor Interface (visible by default)
|
| 148 |
with gr.Column(
|
|
@@ -330,6 +332,7 @@ with gr.Blocks(
|
|
| 330 |
game_image,
|
| 331 |
game_choices,
|
| 332 |
custom_choice,
|
|
|
|
| 333 |
],
|
| 334 |
)
|
| 335 |
|
|
@@ -362,9 +365,9 @@ with gr.Blocks(
|
|
| 362 |
inputs=[],
|
| 363 |
outputs=[ls_user_hash],
|
| 364 |
)
|
| 365 |
-
|
| 366 |
fn=update_audio,
|
| 367 |
-
inputs=[ls_user_hash],
|
| 368 |
outputs=[audio_out],
|
| 369 |
)
|
| 370 |
|
|
|
|
| 118 |
gr.update(),
|
| 119 |
gr.update(), # game components unchanged
|
| 120 |
gr.update(), # custom choice unchanged
|
| 121 |
+
gr.update(),
|
| 122 |
)
|
| 123 |
|
| 124 |
# First, get the game interface updates
|
|
|
|
| 144 |
gr.HTML("<div class='loading-text'>🚀 Starting your adventure...</div>")
|
| 145 |
|
| 146 |
ls_user_hash = gr.BrowserState("", "user_hash")
|
| 147 |
+
ls_game_started = gr.BrowserState(False, "game_started")
|
| 148 |
|
| 149 |
# Constructor Interface (visible by default)
|
| 150 |
with gr.Column(
|
|
|
|
| 332 |
game_image,
|
| 333 |
game_choices,
|
| 334 |
custom_choice,
|
| 335 |
+
ls_game_started,
|
| 336 |
],
|
| 337 |
)
|
| 338 |
|
|
|
|
| 365 |
inputs=[],
|
| 366 |
outputs=[ls_user_hash],
|
| 367 |
)
|
| 368 |
+
ls_game_started.change(
|
| 369 |
fn=update_audio,
|
| 370 |
+
inputs=[ls_user_hash, ls_game_started],
|
| 371 |
outputs=[audio_out],
|
| 372 |
)
|
| 373 |
|