Spaces:
Running
Running
fix: parallel game generation
Browse files- src/agent/llm_graph.py +5 -1
- src/audio/audio_generator.py +5 -0
- src/main.py +15 -10
src/agent/llm_graph.py
CHANGED
|
@@ -60,7 +60,11 @@ async def node_init_game(state: GraphState) -> GraphState:
|
|
| 60 |
first_scene = await generate_scene.ainvoke(
|
| 61 |
{"user_hash": state.user_hash, "last_choice": "start"}
|
| 62 |
)
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
logger.info(f"Change scene: {change_scene}")
|
| 65 |
await generate_scene_image.ainvoke(
|
| 66 |
{
|
|
|
|
| 60 |
first_scene = await generate_scene.ainvoke(
|
| 61 |
{"user_hash": state.user_hash, "last_choice": "start"}
|
| 62 |
)
|
| 63 |
+
init_description = (
|
| 64 |
+
f"{first_scene['description']}\n"
|
| 65 |
+
"NOTE FOR THE ASSISTANT: YOU MUST GENERATE A NEW IMAGE FOR THE STARTING SCENE"
|
| 66 |
+
)
|
| 67 |
+
change_scene = await generate_image_prompt(state.user_hash, init_description)
|
| 68 |
logger.info(f"Change scene: {change_scene}")
|
| 69 |
await generate_scene_image.ainvoke(
|
| 70 |
{
|
src/audio/audio_generator.py
CHANGED
|
@@ -14,6 +14,7 @@ client = genai.Client(api_key=settings.gemini_api_key.get_secret_value(), http_o
|
|
| 14 |
|
| 15 |
async def generate_music(user_hash: str, music_tone: str, receive_audio):
|
| 16 |
if user_hash in sessions:
|
|
|
|
| 17 |
return
|
| 18 |
async with (
|
| 19 |
client.aio.live.music.connect(model='models/lyria-realtime-exp') as session,
|
|
@@ -85,6 +86,10 @@ async def cleanup_music_session(user_hash: str):
|
|
| 85 |
|
| 86 |
def update_audio(user_hash):
|
| 87 |
"""Continuously stream audio from the queue as WAV bytes."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
while True:
|
| 89 |
if user_hash not in sessions:
|
| 90 |
time.sleep(0.5)
|
|
|
|
| 14 |
|
| 15 |
async def generate_music(user_hash: str, music_tone: str, receive_audio):
|
| 16 |
if user_hash in sessions:
|
| 17 |
+
logger.info(f"Music generation already started for user hash {user_hash}, skipping new generation")
|
| 18 |
return
|
| 19 |
async with (
|
| 20 |
client.aio.live.music.connect(model='models/lyria-realtime-exp') as session,
|
|
|
|
| 86 |
|
| 87 |
def update_audio(user_hash):
|
| 88 |
"""Continuously stream audio from the queue as WAV bytes."""
|
| 89 |
+
if user_hash == "":
|
| 90 |
+
return
|
| 91 |
+
|
| 92 |
+
logger.info(f"Starting audio update loop for user hash: {user_hash}")
|
| 93 |
while True:
|
| 94 |
if user_hash not in sessions:
|
| 95 |
time.sleep(0.5)
|
src/main.py
CHANGED
|
@@ -5,8 +5,6 @@ from audio.audio_generator import (
|
|
| 5 |
cleanup_music_session,
|
| 6 |
)
|
| 7 |
import logging
|
| 8 |
-
from agent.llm_agent import process_user_input
|
| 9 |
-
from images.image_generator import modify_image
|
| 10 |
from agent.runner import process_step
|
| 11 |
import uuid
|
| 12 |
from game_constructor import (
|
|
@@ -17,9 +15,8 @@ from game_constructor import (
|
|
| 17 |
load_character_suggestion,
|
| 18 |
start_game_with_settings,
|
| 19 |
)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
from config import settings
|
| 23 |
|
| 24 |
|
| 25 |
logger = logging.getLogger(__name__)
|
|
@@ -37,10 +34,11 @@ async def return_to_constructor(user_hash: str):
|
|
| 37 |
gr.update(visible=False), # game_interface
|
| 38 |
gr.update(visible=False), # error_message
|
| 39 |
)
|
| 40 |
-
|
| 41 |
async def generate_user_hash():
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
async def update_scene(user_hash: str, choice):
|
| 46 |
logger.info(f"Updating scene with choice: {choice}")
|
|
@@ -333,6 +331,7 @@ with gr.Blocks(
|
|
| 333 |
game_choices,
|
| 334 |
custom_choice,
|
| 335 |
],
|
|
|
|
| 336 |
)
|
| 337 |
|
| 338 |
back_btn.click(
|
|
@@ -350,21 +349,27 @@ with gr.Blocks(
|
|
| 350 |
fn=update_scene,
|
| 351 |
inputs=[local_storage, game_choices],
|
| 352 |
outputs=[game_text, game_image, game_choices, custom_choice],
|
|
|
|
| 353 |
)
|
| 354 |
|
| 355 |
custom_choice.submit(
|
| 356 |
fn=update_scene,
|
| 357 |
inputs=[local_storage, custom_choice],
|
| 358 |
outputs=[game_text, game_image, game_choices, custom_choice],
|
|
|
|
| 359 |
)
|
| 360 |
|
| 361 |
-
demo.load(fn=generate_user_hash, outputs=[local_storage])
|
| 362 |
-
|
| 363 |
demo.unload(cleanup_music_session)
|
| 364 |
demo.load(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
fn=update_audio,
|
| 366 |
inputs=[local_storage],
|
| 367 |
outputs=[audio_out],
|
|
|
|
| 368 |
)
|
| 369 |
|
| 370 |
demo.launch(ssr_mode=False)
|
|
|
|
| 5 |
cleanup_music_session,
|
| 6 |
)
|
| 7 |
import logging
|
|
|
|
|
|
|
| 8 |
from agent.runner import process_step
|
| 9 |
import uuid
|
| 10 |
from game_constructor import (
|
|
|
|
| 15 |
load_character_suggestion,
|
| 16 |
start_game_with_settings,
|
| 17 |
)
|
| 18 |
+
|
| 19 |
+
CONCURRENCY_LIMIT = 100
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
logger = logging.getLogger(__name__)
|
|
|
|
| 34 |
gr.update(visible=False), # game_interface
|
| 35 |
gr.update(visible=False), # error_message
|
| 36 |
)
|
| 37 |
+
|
| 38 |
async def generate_user_hash():
|
| 39 |
+
hash = str(uuid.uuid4())
|
| 40 |
+
logger.info(f"Generated user hash: {hash}")
|
| 41 |
+
return gr.update(value=hash)
|
| 42 |
|
| 43 |
async def update_scene(user_hash: str, choice):
|
| 44 |
logger.info(f"Updating scene with choice: {choice}")
|
|
|
|
| 331 |
game_choices,
|
| 332 |
custom_choice,
|
| 333 |
],
|
| 334 |
+
concurrency_limit=CONCURRENCY_LIMIT,
|
| 335 |
)
|
| 336 |
|
| 337 |
back_btn.click(
|
|
|
|
| 349 |
fn=update_scene,
|
| 350 |
inputs=[local_storage, game_choices],
|
| 351 |
outputs=[game_text, game_image, game_choices, custom_choice],
|
| 352 |
+
concurrency_limit=CONCURRENCY_LIMIT,
|
| 353 |
)
|
| 354 |
|
| 355 |
custom_choice.submit(
|
| 356 |
fn=update_scene,
|
| 357 |
inputs=[local_storage, custom_choice],
|
| 358 |
outputs=[game_text, game_image, game_choices, custom_choice],
|
| 359 |
+
concurrency_limit=CONCURRENCY_LIMIT,
|
| 360 |
)
|
| 361 |
|
|
|
|
|
|
|
| 362 |
demo.unload(cleanup_music_session)
|
| 363 |
demo.load(
|
| 364 |
+
fn=generate_user_hash,
|
| 365 |
+
inputs=[],
|
| 366 |
+
outputs=[local_storage],
|
| 367 |
+
)
|
| 368 |
+
local_storage.change(
|
| 369 |
fn=update_audio,
|
| 370 |
inputs=[local_storage],
|
| 371 |
outputs=[audio_out],
|
| 372 |
+
concurrency_limit=CONCURRENCY_LIMIT,
|
| 373 |
)
|
| 374 |
|
| 375 |
demo.launch(ssr_mode=False)
|