Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,6 +32,15 @@ sentence_templates = {
|
|
| 32 |
"Dialogue": "Someone spoke with a {property} tone: {word}"
|
| 33 |
}
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Pure Python function to augment word lists from user input
|
| 36 |
def augment_word_lists(user_input):
|
| 37 |
augmented_lists = {key: list(set(val)) for key, val in default_word_lists.items()}
|
|
@@ -79,7 +88,6 @@ def assign_card_to_class(card_index):
|
|
| 79 |
|
| 80 |
# Generate card visualization with p5.js
|
| 81 |
def generate_card_visualization(suit, rank, story_class, word, property):
|
| 82 |
-
# Parameterize animation based on card properties
|
| 83 |
num_balls = rank * 5 # More balls for higher rank
|
| 84 |
jelly_size = {"Hearts": 40, "Diamonds": 50, "Clubs": 30, "Spades": 60}[suit] # Suit affects jellyfish size
|
| 85 |
rotation_speed = {"Location": 0.005, "Actions": 0.01, "Thoughts": 0.003, "Emotions": 0.007, "Dialogue": 0.009}[story_class]
|
|
@@ -239,6 +247,10 @@ def generate_card_visualization(suit, rank, story_class, word, property):
|
|
| 239 |
def generate_story_sentence(story_class, word, property):
|
| 240 |
return sentence_templates[story_class].format(word=word, property=property)
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# Generate song lyrics
|
| 243 |
def generate_song_lyrics(story_text):
|
| 244 |
words = story_text.split()
|
|
@@ -248,8 +260,8 @@ def generate_song_lyrics(story_text):
|
|
| 248 |
|
| 249 |
# Main app
|
| 250 |
def main():
|
| 251 |
-
st.set_page_config(page_title="StoryForge: The Animated
|
| 252 |
-
st.title("π΄ StoryForge:
|
| 253 |
|
| 254 |
# User input
|
| 255 |
st.markdown("## π Your Story Seed")
|
|
@@ -264,6 +276,12 @@ def main():
|
|
| 264 |
st.session_state.story = []
|
| 265 |
if "drawn_cards" not in st.session_state:
|
| 266 |
st.session_state.drawn_cards = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
# Process input
|
| 269 |
if st.button("Start Game"):
|
|
@@ -271,12 +289,17 @@ def main():
|
|
| 271 |
st.session_state.augmented_lists = augment_word_lists(user_input)
|
| 272 |
st.session_state.deck = create_deck()
|
| 273 |
st.session_state.story = []
|
|
|
|
| 274 |
st.session_state.drawn_cards = 0
|
|
|
|
|
|
|
| 275 |
st.success("Game started! Draw your first card.")
|
| 276 |
|
| 277 |
-
#
|
| 278 |
col1, col2 = st.columns([2, 3])
|
|
|
|
| 279 |
with col1:
|
|
|
|
| 280 |
if st.button("Draw Card") and st.session_state.drawn_cards < 52:
|
| 281 |
card_index = st.session_state.drawn_cards
|
| 282 |
suit, rank = st.session_state.deck[card_index]
|
|
@@ -288,15 +311,31 @@ def main():
|
|
| 288 |
viz_html = generate_card_visualization(suit, rank, story_class, word, property)
|
| 289 |
st.components.v1.html(viz_html, height=420, scrolling=False)
|
| 290 |
|
| 291 |
-
# Generate story sentence
|
| 292 |
sentence = generate_story_sentence(story_class, word, property)
|
| 293 |
st.session_state.story.append(sentence)
|
|
|
|
|
|
|
| 294 |
st.session_state.drawn_cards += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
with col2:
|
| 297 |
st.markdown("### π Your Story Unfolds")
|
| 298 |
if st.session_state.story:
|
| 299 |
st.write("\n".join(st.session_state.story))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
# Song generation
|
| 302 |
if st.session_state.drawn_cards == 52:
|
|
|
|
| 32 |
"Dialogue": "Someone spoke with a {property} tone: {word}"
|
| 33 |
}
|
| 34 |
|
| 35 |
+
# Choice templates for branching narrative
|
| 36 |
+
choice_templates = {
|
| 37 |
+
"Location": ["Explore the {word} further.", "Leave the {word} behind."],
|
| 38 |
+
"Actions": ["Continue {word} despite the risk.", "Stop {word} and reconsider."],
|
| 39 |
+
"Thoughts": ["Pursue the '{word}' idea.", "Ignore the '{word}' thought."],
|
| 40 |
+
"Emotions": ["Embrace the {word}.", "Suppress the {word}."],
|
| 41 |
+
"Dialogue": ["Respond to {word}.", "Ignore {word} and move on."]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
# Pure Python function to augment word lists from user input
|
| 45 |
def augment_word_lists(user_input):
|
| 46 |
augmented_lists = {key: list(set(val)) for key, val in default_word_lists.items()}
|
|
|
|
| 88 |
|
| 89 |
# Generate card visualization with p5.js
|
| 90 |
def generate_card_visualization(suit, rank, story_class, word, property):
|
|
|
|
| 91 |
num_balls = rank * 5 # More balls for higher rank
|
| 92 |
jelly_size = {"Hearts": 40, "Diamonds": 50, "Clubs": 30, "Spades": 60}[suit] # Suit affects jellyfish size
|
| 93 |
rotation_speed = {"Location": 0.005, "Actions": 0.01, "Thoughts": 0.003, "Emotions": 0.007, "Dialogue": 0.009}[story_class]
|
|
|
|
| 247 |
def generate_story_sentence(story_class, word, property):
|
| 248 |
return sentence_templates[story_class].format(word=word, property=property)
|
| 249 |
|
| 250 |
+
# Generate choice options
|
| 251 |
+
def generate_choices(story_class, word):
|
| 252 |
+
return [template.format(word=word) for template in choice_templates[story_class]]
|
| 253 |
+
|
| 254 |
# Generate song lyrics
|
| 255 |
def generate_song_lyrics(story_text):
|
| 256 |
words = story_text.split()
|
|
|
|
| 260 |
|
| 261 |
# Main app
|
| 262 |
def main():
|
| 263 |
+
st.set_page_config(page_title="StoryForge: The Animated Adventure", page_icon="π΄", layout="wide")
|
| 264 |
+
st.title("π΄ StoryForge: A Choose Your Own Adventure Game π΄")
|
| 265 |
|
| 266 |
# User input
|
| 267 |
st.markdown("## π Your Story Seed")
|
|
|
|
| 276 |
st.session_state.story = []
|
| 277 |
if "drawn_cards" not in st.session_state:
|
| 278 |
st.session_state.drawn_cards = 0
|
| 279 |
+
if "history" not in st.session_state:
|
| 280 |
+
st.session_state.history = []
|
| 281 |
+
if "current_choices" not in st.session_state:
|
| 282 |
+
st.session_state.current_choices = []
|
| 283 |
+
if "last_card" not in st.session_state:
|
| 284 |
+
st.session_state.last_card = None
|
| 285 |
|
| 286 |
# Process input
|
| 287 |
if st.button("Start Game"):
|
|
|
|
| 289 |
st.session_state.augmented_lists = augment_word_lists(user_input)
|
| 290 |
st.session_state.deck = create_deck()
|
| 291 |
st.session_state.story = []
|
| 292 |
+
st.session_state.history = []
|
| 293 |
st.session_state.drawn_cards = 0
|
| 294 |
+
st.session_state.current_choices = []
|
| 295 |
+
st.session_state.last_card = None
|
| 296 |
st.success("Game started! Draw your first card.")
|
| 297 |
|
| 298 |
+
# Layout
|
| 299 |
col1, col2 = st.columns([2, 3])
|
| 300 |
+
|
| 301 |
with col1:
|
| 302 |
+
# Draw card
|
| 303 |
if st.button("Draw Card") and st.session_state.drawn_cards < 52:
|
| 304 |
card_index = st.session_state.drawn_cards
|
| 305 |
suit, rank = st.session_state.deck[card_index]
|
|
|
|
| 311 |
viz_html = generate_card_visualization(suit, rank, story_class, word, property)
|
| 312 |
st.components.v1.html(viz_html, height=420, scrolling=False)
|
| 313 |
|
| 314 |
+
# Generate story sentence and choices
|
| 315 |
sentence = generate_story_sentence(story_class, word, property)
|
| 316 |
st.session_state.story.append(sentence)
|
| 317 |
+
st.session_state.current_choices = generate_choices(story_class, word)
|
| 318 |
+
st.session_state.last_card = (suit, rank, story_class, word, property)
|
| 319 |
st.session_state.drawn_cards += 1
|
| 320 |
+
|
| 321 |
+
# Display choices
|
| 322 |
+
if st.session_state.current_choices:
|
| 323 |
+
st.markdown("#### Make Your Choice:")
|
| 324 |
+
choice = st.radio("What happens next?", st.session_state.current_choices)
|
| 325 |
+
if st.button("Confirm Choice"):
|
| 326 |
+
st.session_state.history.append((st.session_state.story[-1], choice))
|
| 327 |
+
st.session_state.current_choices = []
|
| 328 |
+
st.success(f"Choice made: {choice}")
|
| 329 |
|
| 330 |
with col2:
|
| 331 |
st.markdown("### π Your Story Unfolds")
|
| 332 |
if st.session_state.story:
|
| 333 |
st.write("\n".join(st.session_state.story))
|
| 334 |
+
|
| 335 |
+
st.markdown("### π°οΈ Adventure History")
|
| 336 |
+
if st.session_state.history:
|
| 337 |
+
for i, (event, choice) in enumerate(st.session_state.history):
|
| 338 |
+
st.write(f"**Step {i+1}**: {event} β *Choice: {choice}*")
|
| 339 |
|
| 340 |
# Song generation
|
| 341 |
if st.session_state.drawn_cards == 52:
|