Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -103,11 +103,9 @@ For each response you MUST:
|
|
103 |
3. Include dialogue or your character's thoughts that reveal personality and motivations
|
104 |
4. Create a strong sense of atmosphere appropriate for {selected_genre}
|
105 |
5. End with EXACTLY THREE numbered choices and NOTHING ELSE AFTER THEM:
|
106 |
-
|
107 |
1. [Complete sentence in second-person starting with a verb]
|
108 |
2. [Complete sentence in second-person starting with a verb]
|
109 |
3. [Complete sentence in second-person starting with a verb]
|
110 |
-
|
111 |
CRITICAL RULES:
|
112 |
- Provide only ONE set of three choices at the very end of your response
|
113 |
- Never continue the story after giving choices
|
@@ -115,7 +113,6 @@ CRITICAL RULES:
|
|
115 |
- Keep all narrative before the choices
|
116 |
- End every response with exactly three numbered options
|
117 |
- Each choice must start with "You" followed by a verb
|
118 |
-
|
119 |
Remember: The story continues ONLY when the player makes a choice."""
|
120 |
return system_message
|
121 |
|
@@ -186,19 +183,24 @@ def respond(message: str, chat_history: List[Tuple[str, str]], genre: Optional[s
|
|
186 |
def save_story(chat_history):
|
187 |
"""Convert chat history to markdown and return as downloadable file"""
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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():
|
@@ -210,7 +212,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
210 |
# Header section with improved instructions
|
211 |
gr.Markdown("""
|
212 |
# 🔮 AI Story Studio
|
213 |
-
|
214 |
This AI-powered storytelling experience is a collaboration between you and AI—building a world, scene by scene.
|
215 |
You lead the way with your choices, and AI responds, expanding on your ideas.
|
216 |
|
@@ -218,7 +219,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
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 |
""")
|
@@ -342,13 +342,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
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=
|
|
|
352 |
)
|
353 |
|
354 |
# Initialize buttons with default fantasy genre examples
|
|
|
103 |
3. Include dialogue or your character's thoughts that reveal personality and motivations
|
104 |
4. Create a strong sense of atmosphere appropriate for {selected_genre}
|
105 |
5. End with EXACTLY THREE numbered choices and NOTHING ELSE AFTER THEM:
|
|
|
106 |
1. [Complete sentence in second-person starting with a verb]
|
107 |
2. [Complete sentence in second-person starting with a verb]
|
108 |
3. [Complete sentence in second-person starting with a verb]
|
|
|
109 |
CRITICAL RULES:
|
110 |
- Provide only ONE set of three choices at the very end of your response
|
111 |
- Never continue the story after giving choices
|
|
|
113 |
- Keep all narrative before the choices
|
114 |
- End every response with exactly three numbered options
|
115 |
- Each choice must start with "You" followed by a verb
|
|
|
116 |
Remember: The story continues ONLY when the player makes a choice."""
|
117 |
return system_message
|
118 |
|
|
|
183 |
def save_story(chat_history):
|
184 |
"""Convert chat history to markdown and return as downloadable file"""
|
185 |
if not chat_history:
|
186 |
+
return gr.File.update(value=None)
|
187 |
|
188 |
try:
|
189 |
story_text = "# My Interactive Adventure\n\n"
|
|
|
190 |
for user_msg, bot_msg in chat_history:
|
191 |
story_text += f"**Player:** {user_msg}\n\n"
|
192 |
story_text += f"**Story:** {bot_msg}\n\n---\n\n"
|
193 |
|
194 |
+
# Create temporary file
|
195 |
+
temp_file = "temp_story.md"
|
196 |
+
with open(temp_file, "w", encoding="utf-8") as f:
|
197 |
+
f.write(story_text)
|
198 |
+
|
199 |
+
return temp_file
|
200 |
+
|
201 |
except Exception as e:
|
202 |
logging.error(f"Error saving story: {e}")
|
203 |
+
return gr.File.update(value=None)
|
204 |
|
205 |
# Add this function to get a custom avatar image URL
|
206 |
def get_storyteller_avatar_url():
|
|
|
212 |
# Header section with improved instructions
|
213 |
gr.Markdown("""
|
214 |
# 🔮 AI Story Studio
|
|
|
215 |
This AI-powered storytelling experience is a collaboration between you and AI—building a world, scene by scene.
|
216 |
You lead the way with your choices, and AI responds, expanding on your ideas.
|
217 |
|
|
|
219 |
* Pick a genre that sparks your imagination
|
220 |
* Choose a Story Starter or start from scratch
|
221 |
* Work with AI—describe your actions, make decisions, and see how the story unfolds together
|
|
|
222 |
|
223 |
> **Tip:** The more detail you provide, the deeper the story becomes.
|
224 |
""")
|
|
|
342 |
label="Download your story",
|
343 |
file_count="single",
|
344 |
file_types=[".md"],
|
345 |
+
interactive=False,
|
346 |
+
visible=True
|
347 |
)
|
348 |
|
349 |
save_btn.click(
|
350 |
fn=save_story,
|
351 |
inputs=[chatbot],
|
352 |
+
outputs=story_output,
|
353 |
+
queue=False # Process immediately
|
354 |
)
|
355 |
|
356 |
# Initialize buttons with default fantasy genre examples
|