Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,17 +102,21 @@ For each response you MUST:
|
|
| 102 |
2. Always use second-person perspective ("you", "your") to maintain reader immersion
|
| 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
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
- Each choice must start with "You" followed by a verb
|
| 114 |
-
|
| 115 |
-
|
| 116 |
return system_message
|
| 117 |
|
| 118 |
def create_story_summary(chat_history):
|
|
@@ -178,15 +182,16 @@ def respond(message: str, chat_history: List[Tuple[str, str]], genre: Optional[s
|
|
| 178 |
return "", chat_history + [(message, error_msg)]
|
| 179 |
|
| 180 |
def save_story(chat_history):
|
| 181 |
-
"""Convert chat history to markdown
|
| 182 |
if not chat_history:
|
| 183 |
-
return
|
| 184 |
|
| 185 |
story_text = "# My Interactive Adventure\n\n"
|
| 186 |
for user_msg, bot_msg in chat_history:
|
| 187 |
story_text += f"**Player:** {user_msg}\n\n"
|
| 188 |
story_text += f"**Story:** {bot_msg}\n\n---\n\n"
|
| 189 |
|
|
|
|
| 190 |
return story_text
|
| 191 |
|
| 192 |
# Add this function to get a custom avatar image URL
|
|
@@ -198,7 +203,7 @@ def get_storyteller_avatar_url():
|
|
| 198 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 199 |
# Header section with improved instructions
|
| 200 |
gr.Markdown("""
|
| 201 |
-
# 🔮
|
| 202 |
|
| 203 |
This AI-powered storytelling experience is a collaboration between you and AI—building a world, scene by scene.
|
| 204 |
You lead the way with your choices, and AI responds, expanding on your ideas.
|
|
@@ -332,15 +337,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 332 |
# "Download My Story" row
|
| 333 |
with gr.Row():
|
| 334 |
save_btn = gr.Button("Download My Story", variant="secondary")
|
| 335 |
-
story_output = gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
-
save_btn.click(save_story, inputs=[chatbot], outputs=[story_output])
|
| 338 |
save_btn.click(
|
| 339 |
-
fn=lambda:
|
| 340 |
-
inputs=
|
| 341 |
-
outputs=story_output
|
| 342 |
-
js="() => {document.getElementById('story_output').scrollIntoView();}",
|
| 343 |
-
queue=False
|
| 344 |
)
|
| 345 |
|
| 346 |
# Initialize buttons with default fantasy genre examples
|
|
|
|
| 102 |
2. Always use second-person perspective ("you", "your") to maintain reader immersion
|
| 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
|
| 114 |
+
- Never provide additional choices
|
| 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 |
|
| 122 |
def create_story_summary(chat_history):
|
|
|
|
| 182 |
return "", chat_history + [(message, error_msg)]
|
| 183 |
|
| 184 |
def save_story(chat_history):
|
| 185 |
+
"""Convert chat history to markdown and return as downloadable file"""
|
| 186 |
if not chat_history:
|
| 187 |
+
return None
|
| 188 |
|
| 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 |
+
# Return as a file for download
|
| 195 |
return story_text
|
| 196 |
|
| 197 |
# Add this function to get a custom avatar image URL
|
|
|
|
| 203 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 204 |
# Header section with improved instructions
|
| 205 |
gr.Markdown("""
|
| 206 |
+
# 🔮 AI Story Studio
|
| 207 |
|
| 208 |
This AI-powered storytelling experience is a collaboration between you and AI—building a world, scene by scene.
|
| 209 |
You lead the way with your choices, and AI responds, expanding on your ideas.
|
|
|
|
| 337 |
# "Download My Story" row
|
| 338 |
with gr.Row():
|
| 339 |
save_btn = gr.Button("Download My Story", variant="secondary")
|
| 340 |
+
story_output = gr.File(
|
| 341 |
+
label="Download your story",
|
| 342 |
+
file_count="single",
|
| 343 |
+
type="string",
|
| 344 |
+
file_types=[".md"]
|
| 345 |
+
)
|
| 346 |
|
|
|
|
| 347 |
save_btn.click(
|
| 348 |
+
fn=lambda x: (save_story(x), "story.md") if x else None,
|
| 349 |
+
inputs=[chatbot],
|
| 350 |
+
outputs=[story_output]
|
|
|
|
|
|
|
| 351 |
)
|
| 352 |
|
| 353 |
# Initialize buttons with default fantasy genre examples
|