PeterPinetree commited on
Commit
73564ce
·
verified ·
1 Parent(s): 87c9853

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -188,14 +188,17 @@ def save_story(chat_history):
188
  if not chat_history:
189
  return None
190
 
191
- story_text = "# My Interactive Adventure\n\n"
192
- # Process chat history (already in tuples of user, bot messages)
193
- for user_msg, bot_msg in chat_history:
194
- story_text += f"**Player:** {user_msg}\n\n"
195
- story_text += f"**Story:** {bot_msg}\n\n---\n\n"
196
-
197
- # Return as bytes for download
198
- return story_text.encode('utf-8')
 
 
 
199
 
200
  # Add this function to get a custom avatar image URL
201
  def get_storyteller_avatar_url():
@@ -212,9 +215,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
212
  You lead the way with your choices, and AI responds, expanding on your ideas.
213
 
214
  ### How to Play:
215
- 1. Describe what you want to do next *(Example: "I step into the ancient library, searching for hidden scrolls")*
216
- 2. Follow one of the AI's suggestions or write your own next move
217
- 3. Keep going! The AI remembers your choices and helps shape the evolving adventure
 
218
 
219
  > **Tip:** The more detail you provide, the deeper the story becomes.
220
  """)
@@ -337,11 +341,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
337
  story_output = gr.File(
338
  label="Download your story",
339
  file_count="single",
340
- file_types=[".md"]
 
341
  )
342
 
343
  save_btn.click(
344
- fn=lambda x: {"name": "story.md", "data": save_story(x)} if x else None,
345
  inputs=[chatbot],
346
  outputs=[story_output]
347
  )
 
188
  if not chat_history:
189
  return None
190
 
191
+ try:
192
+ story_text = "# My Interactive Adventure\n\n"
193
+ # Process chat history (already in tuples of user, bot messages)
194
+ for user_msg, bot_msg in chat_history:
195
+ story_text += f"**Player:** {user_msg}\n\n"
196
+ story_text += f"**Story:** {bot_msg}\n\n---\n\n"
197
+
198
+ return {"name": "my_adventure.md", "data": story_text.encode('utf-8')}
199
+ except Exception as e:
200
+ logging.error(f"Error saving story: {e}")
201
+ return None
202
 
203
  # Add this function to get a custom avatar image URL
204
  def get_storyteller_avatar_url():
 
215
  You lead the way with your choices, and AI responds, expanding on your ideas.
216
 
217
  ### How to Play:
218
+ * Pick a genre that sparks your imagination
219
+ * Choose a Story Starter or start from scratch
220
+ * Work with AI—describe your actions, make decisions, and see how the story unfolds together
221
+
222
 
223
  > **Tip:** The more detail you provide, the deeper the story becomes.
224
  """)
 
341
  story_output = gr.File(
342
  label="Download your story",
343
  file_count="single",
344
+ file_types=[".md"],
345
+ interactive=False
346
  )
347
 
348
  save_btn.click(
349
+ fn=save_story,
350
  inputs=[chatbot],
351
  outputs=[story_output]
352
  )