Abbasid commited on
Commit
94d73ce
·
verified ·
1 Parent(s): 78c1caf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -139,6 +139,8 @@ class StorytellerWorkflow(Workflow):
139
  # app.py
140
 
141
  # The only change is in the function definition line
 
 
142
  async def run_turn(user_input, game_state, image_display, story_display, inventory_display):
143
  if game_state is None:
144
  game_state = {'inventory': [], 'last_story_part': None}
@@ -164,6 +166,7 @@ async def run_turn(user_input, game_state, image_display, story_display, invento
164
 
165
  if isinstance(result_event, StoryContext):
166
  narrative, choices = result_event.story_part.split("Choices:", 1)
 
167
  story_display_text = f"{textwrap.fill(narrative, width=80)}\n\nChoices:{choices}"
168
 
169
  new_game_state = {
@@ -172,20 +175,20 @@ async def run_turn(user_input, game_state, image_display, story_display, invento
172
  }
173
  inventory_text = f"**Inventory:** {', '.join(new_game_state['inventory']) if new_game_state['inventory'] else 'Empty'}"
174
 
175
- # Instantly yield the text
 
176
  yield {
177
- image_display: None,
178
  story_display: story_display_text,
179
  inventory_display: inventory_text,
180
  game_state: new_game_state
181
  }
182
 
183
- # Generate the image
184
  image_path = None
185
  if HF_TOKEN:
186
  image_path = await generate_image(narrative, HF_TOKEN)
187
 
188
- # Yield the final update with the image when it's ready
189
  if image_path:
190
  yield {
191
  image_display: image_path
 
139
  # app.py
140
 
141
  # The only change is in the function definition line
142
+ # app.py
143
+
144
  async def run_turn(user_input, game_state, image_display, story_display, inventory_display):
145
  if game_state is None:
146
  game_state = {'inventory': [], 'last_story_part': None}
 
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
  }
176
  inventory_text = f"**Inventory:** {', '.join(new_game_state['inventory']) if new_game_state['inventory'] else 'Empty'}"
177
 
178
+ # --- KEY CHANGE: THE CORRECT YIELD SYNTAX ---
179
+ # First, instantly yield the text and state update
180
  yield {
 
181
  story_display: story_display_text,
182
  inventory_display: inventory_text,
183
  game_state: new_game_state
184
  }
185
 
186
+ # Then, generate the image in the background
187
  image_path = None
188
  if HF_TOKEN:
189
  image_path = await generate_image(narrative, HF_TOKEN)
190
 
191
+ # Finally, yield a second update ONLY for the image component
192
  if image_path:
193
  yield {
194
  image_display: image_path