Spaces:
Running
Running
Georgii Savin
commited on
fix: generate new user hash only on load
Browse files- src/main.py +6 -5
src/main.py
CHANGED
@@ -31,16 +31,16 @@ async def return_to_constructor(user_hash: str):
|
|
31 |
|
32 |
await reset_user_state(user_hash)
|
33 |
await cleanup_music_session(user_hash)
|
34 |
-
# Generate a new hash to avoid stale state
|
35 |
-
new_hash = str(uuid.uuid4())
|
36 |
return (
|
37 |
gr.update(visible=False), # loading_indicator
|
38 |
gr.update(visible=True), # constructor_interface
|
39 |
gr.update(visible=False), # game_interface
|
40 |
gr.update(visible=False), # error_message
|
41 |
-
gr.update(value=new_hash), # local_storage
|
42 |
)
|
43 |
|
|
|
|
|
|
|
44 |
|
45 |
async def update_scene(user_hash: str, choice):
|
46 |
logger.info(f"Updating scene with choice: {choice}")
|
@@ -138,7 +138,7 @@ with gr.Blocks(
|
|
138 |
with gr.Column(visible=False, elem_id="loading-indicator") as loading_indicator:
|
139 |
gr.HTML("<div class='loading-text'>🚀 Starting your adventure...</div>")
|
140 |
|
141 |
-
local_storage = gr.BrowserState(
|
142 |
|
143 |
# Constructor Interface (visible by default)
|
144 |
with gr.Column(
|
@@ -343,7 +343,6 @@ with gr.Blocks(
|
|
343 |
constructor_interface,
|
344 |
game_interface,
|
345 |
error_message,
|
346 |
-
local_storage,
|
347 |
],
|
348 |
)
|
349 |
|
@@ -359,6 +358,8 @@ with gr.Blocks(
|
|
359 |
outputs=[game_text, game_image, game_choices, custom_choice],
|
360 |
)
|
361 |
|
|
|
|
|
362 |
demo.unload(cleanup_music_session)
|
363 |
demo.load(
|
364 |
fn=update_audio,
|
|
|
31 |
|
32 |
await reset_user_state(user_hash)
|
33 |
await cleanup_music_session(user_hash)
|
|
|
|
|
34 |
return (
|
35 |
gr.update(visible=False), # loading_indicator
|
36 |
gr.update(visible=True), # constructor_interface
|
37 |
gr.update(visible=False), # game_interface
|
38 |
gr.update(visible=False), # error_message
|
|
|
39 |
)
|
40 |
|
41 |
+
async def generate_user_hash():
|
42 |
+
new_hash = str(uuid.uuid4())
|
43 |
+
return gr.update(value=new_hash)
|
44 |
|
45 |
async def update_scene(user_hash: str, choice):
|
46 |
logger.info(f"Updating scene with choice: {choice}")
|
|
|
138 |
with gr.Column(visible=False, elem_id="loading-indicator") as loading_indicator:
|
139 |
gr.HTML("<div class='loading-text'>🚀 Starting your adventure...</div>")
|
140 |
|
141 |
+
local_storage = gr.BrowserState("", "user_hash")
|
142 |
|
143 |
# Constructor Interface (visible by default)
|
144 |
with gr.Column(
|
|
|
343 |
constructor_interface,
|
344 |
game_interface,
|
345 |
error_message,
|
|
|
346 |
],
|
347 |
)
|
348 |
|
|
|
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,
|