Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -166,7 +166,6 @@ async def run_turn(user_input, game_state, image_display, story_display, invento
|
|
166 |
|
167 |
if isinstance(result_event, StoryContext):
|
168 |
narrative, choices = result_event.story_part.split("Choices:", 1)
|
169 |
-
# We need a different variable name here to avoid conflict with the component object
|
170 |
story_display_text = f"{textwrap.fill(narrative, width=80)}\n\nChoices:{choices}"
|
171 |
|
172 |
new_game_state = {
|
@@ -175,25 +174,25 @@ async def run_turn(user_input, game_state, image_display, story_display, invento
|
|
175 |
}
|
176 |
inventory_text = f"**Inventory:** {', '.join(new_game_state['inventory']) if new_game_state['inventory'] else 'Empty'}"
|
177 |
|
178 |
-
# ---
|
179 |
-
|
|
|
180 |
yield {
|
181 |
story_display: story_display_text,
|
182 |
inventory_display: inventory_text,
|
183 |
-
game_state: new_game_state
|
184 |
}
|
185 |
|
186 |
-
#
|
187 |
image_path = None
|
188 |
if HF_TOKEN:
|
189 |
image_path = await generate_image(narrative, HF_TOKEN)
|
190 |
|
191 |
-
#
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
def create_demo():
|
198 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
199 |
game_state = gr.State(None)
|
|
|
166 |
|
167 |
if isinstance(result_event, StoryContext):
|
168 |
narrative, choices = result_event.story_part.split("Choices:", 1)
|
|
|
169 |
story_display_text = f"{textwrap.fill(narrative, width=80)}\n\nChoices:{choices}"
|
170 |
|
171 |
new_game_state = {
|
|
|
174 |
}
|
175 |
inventory_text = f"**Inventory:** {', '.join(new_game_state['inventory']) if new_game_state['inventory'] else 'Empty'}"
|
176 |
|
177 |
+
# --- THIS IS THE FINAL, CORRECTED LOGIC ---
|
178 |
+
|
179 |
+
# 1. Instantly yield ONLY the visible text components. Do not touch the state yet.
|
180 |
yield {
|
181 |
story_display: story_display_text,
|
182 |
inventory_display: inventory_text,
|
|
|
183 |
}
|
184 |
|
185 |
+
# 2. Generate the image.
|
186 |
image_path = None
|
187 |
if HF_TOKEN:
|
188 |
image_path = await generate_image(narrative, HF_TOKEN)
|
189 |
|
190 |
+
# 3. Yield the final update, containing BOTH the image and the new game state.
|
191 |
+
yield {
|
192 |
+
image_display: image_path,
|
193 |
+
game_state: new_game_state,
|
194 |
+
}
|
195 |
+
|
196 |
def create_demo():
|
197 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
198 |
game_state = gr.State(None)
|