awacke1 commited on
Commit
51269cc
ยท
verified ยท
1 Parent(s): 06493e4

Create Version2.md

Browse files
Files changed (1) hide show
  1. Version2.md +214 -0
Version2.md ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import random
3
+ import re
4
+ from gtts import gTTS
5
+ from PIL import Image, ImageDraw, ImageFont
6
+ import io
7
+ import base64
8
+
9
+ # Default word lists for storytelling classes
10
+ default_word_lists = {
11
+ "Location": ["quiet town", "small village", "city", "forest", "mountain"],
12
+ "Actions": ["walking", "pedaling", "running", "dancing", "exploring"],
13
+ "Thoughts": ["chasing shadows", "what if", "brilliance of years", "echoes", "secrets"],
14
+ "Emotions": ["joy", "pain", "trembling smile", "storm", "silent art"],
15
+ "Dialogue": ["\"Keep moving, dare to feel;\"", "\"Am I chasing shadows?\"", "\"The dawn awaits!\"", "\"I love you.\"", "\"Letโ€™s go!\""]
16
+ }
17
+
18
+ # Suit properties for narrative flavor
19
+ suit_properties = {
20
+ "Hearts": "emotional or romantic",
21
+ "Diamonds": "wealthy or luxurious",
22
+ "Clubs": "conflict or struggle",
23
+ "Spades": "mysterious or dangerous"
24
+ }
25
+
26
+ # Sentence templates for story generation
27
+ sentence_templates = {
28
+ "Location": "The story unfolded in a {property} {word}.",
29
+ "Actions": "Suddenly, a {property} {word} changed everything.",
30
+ "Thoughts": "A {property} thought, '{word}', crossed their mind.",
31
+ "Emotions": "A {property} wave of {word} surged through them.",
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()}
38
+
39
+ # Split input into words
40
+ words = user_input.lower().split()
41
+
42
+ # Simple heuristic lists for categorization
43
+ location_keywords = ["town", "village", "city", "forest", "mountain", "place", "land"]
44
+ action_keywords = ["walk", "run", "dance", "pedal", "explore", "move", "jump"]
45
+ emotion_keywords = ["joy", "pain", "smile", "storm", "fear", "love", "anger"]
46
+
47
+ # Extract dialogues with regex
48
+ dialogues = re.findall(r'"[^"]*"', user_input)
49
+ augmented_lists["Dialogue"].extend(dialogues)
50
+
51
+ # Categorize words
52
+ for word in words:
53
+ if any(keyword in word for keyword in location_keywords):
54
+ augmented_lists["Location"].append(word)
55
+ elif any(keyword in word for keyword in action_keywords):
56
+ augmented_lists["Actions"].append(word)
57
+ elif any(keyword in word for keyword in emotion_keywords):
58
+ augmented_lists["Emotions"].append(word)
59
+ elif "?" in word or "what" in word or "why" in word: # Simple thought detection
60
+ augmented_lists["Thoughts"].append(word)
61
+
62
+ # Remove duplicates
63
+ for key in augmented_lists:
64
+ augmented_lists[key] = list(set(augmented_lists[key]))
65
+
66
+ return augmented_lists
67
+
68
+ # Create a 52-card deck
69
+ def create_deck():
70
+ suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
71
+ ranks = list(range(1, 14))
72
+ deck = [(suit, rank) for suit in suits for rank in ranks]
73
+ random.shuffle(deck)
74
+ return deck
75
+
76
+ # Assign cards to classes
77
+ def assign_card_to_class(card_index):
78
+ if 0 <= card_index < 10:
79
+ return "Location"
80
+ elif 10 <= card_index < 20:
81
+ return "Actions"
82
+ elif 20 <= card_index < 30:
83
+ return "Thoughts"
84
+ elif 30 <= card_index < 40:
85
+ return "Emotions"
86
+ else:
87
+ return "Dialogue"
88
+
89
+ # Generate card image
90
+ def generate_card_image(suit, rank, story_class, word, property):
91
+ img = Image.new("RGB", (200, 300), color="white")
92
+ draw = ImageDraw.Draw(img)
93
+ font = ImageFont.load_default()
94
+
95
+ draw.text((10, 10), f"{rank} of {suit}", fill="black", font=font)
96
+ draw.text((10, 50), f"Class: {story_class}", fill="black", font=font)
97
+ draw.text((10, 90), f"Word: {word}", fill="black", font=font)
98
+ draw.text((10, 130), f"Property: {property}", fill="black", font=font)
99
+
100
+ buffer = io.BytesIO()
101
+ img.save(buffer, format="PNG")
102
+ return buffer.getvalue()
103
+
104
+ # Generate story sentence
105
+ def generate_story_sentence(story_class, word, property):
106
+ return sentence_templates[story_class].format(word=word, property=property)
107
+
108
+ # Generate song lyrics
109
+ def generate_song_lyrics(story_text):
110
+ words = story_text.split()
111
+ key_elements = [word for word in words if len(word) > 3][:12] # Simple filter for ~60 seconds
112
+ lyrics = "\n".join([f"{key_elements[i]} {key_elements[i+1]}" for i in range(0, len(key_elements)-1, 2)])
113
+ return lyrics
114
+
115
+ # Main app
116
+ def main():
117
+ st.set_page_config(page_title="StoryForge: The Game", page_icon="๐ŸŽด", layout="wide")
118
+ st.title("๐ŸŽด StoryForge: A Storytelling Adventure ๐ŸŽด")
119
+
120
+ # User input
121
+ st.markdown("## ๐Ÿ“ Your Story Seed")
122
+ user_input = st.text_area("Paste your story inspiration here:", height=200)
123
+
124
+ # Session state initialization
125
+ if "augmented_lists" not in st.session_state:
126
+ st.session_state.augmented_lists = default_word_lists
127
+ if "deck" not in st.session_state:
128
+ st.session_state.deck = create_deck()
129
+ if "story" not in st.session_state:
130
+ st.session_state.story = []
131
+ if "drawn_cards" not in st.session_state:
132
+ st.session_state.drawn_cards = 0
133
+
134
+ # Process input
135
+ if st.button("Start Game"):
136
+ if user_input:
137
+ st.session_state.augmented_lists = augment_word_lists(user_input)
138
+ st.session_state.deck = create_deck()
139
+ st.session_state.story = []
140
+ st.session_state.drawn_cards = 0
141
+ st.success("Game started! Draw your first card.")
142
+
143
+ # Draw card and story display
144
+ col1, col2 = st.columns([1, 3])
145
+ with col1:
146
+ if st.button("Draw Card") and st.session_state.drawn_cards < 52:
147
+ card_index = st.session_state.drawn_cards
148
+ suit, rank = st.session_state.deck[card_index]
149
+ story_class = assign_card_to_class(card_index)
150
+ word = random.choice(st.session_state.augmented_lists[story_class])
151
+ property = suit_properties[suit]
152
+
153
+ card_image = generate_card_image(suit, rank, story_class, word, property)
154
+ st.image(card_image, caption=f"Card {card_index + 1}")
155
+
156
+ sentence = generate_story_sentence(story_class, word, property)
157
+ st.session_state.story.append(sentence)
158
+ st.session_state.drawn_cards += 1
159
+
160
+ with col2:
161
+ st.markdown("### ๐Ÿ“œ Your Story Unfolds")
162
+ if st.session_state.story:
163
+ st.write("\n".join(st.session_state.story))
164
+
165
+ # Song generation
166
+ if st.session_state.drawn_cards == 52:
167
+ full_story = "\n".join(st.session_state.story)
168
+ st.markdown("### ๐ŸŽต Story Song")
169
+ lyrics = generate_song_lyrics(full_story)
170
+ st.write(lyrics)
171
+
172
+ tts = gTTS(text=lyrics, lang="en")
173
+ audio_file = "story_song.mp3"
174
+ tts.save(audio_file)
175
+ st.audio(audio_file, format="audio/mp3")
176
+
177
+ # Enhanced UI with HTML/CSS
178
+ st.markdown("""
179
+ ## ๐ŸŽฎ Game Board
180
+ <div style="background-color: #f0f0f0; padding: 20px; border-radius: 10px; text-align: center;">
181
+ <h3 style="color: #333;">Draw cards to weave your epic tale!</h3>
182
+ <button style="background-color: #ff9900; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer;"
183
+ onmouseover="this.style.backgroundColor='#cc7700'"
184
+ onmouseout="this.style.backgroundColor='#ff9900'">
185
+ Hover for a surprise!
186
+ </button>
187
+ </div>
188
+ """, unsafe_allow_html=True)
189
+
190
+ # Star layout
191
+ st.markdown("## โญ Five Pillars of Storytelling โญ")
192
+ star_html = """
193
+ <div style="position: relative; width: 400px; height: 400px; margin: auto; border: 1px dashed #aaa; border-radius: 50%;">
194
+ <div style="position: absolute; top: 50px; left: 200px; transform: translate(-50%, -50%); text-align: center;">
195
+ <div style="font-size: 2em;">๐Ÿ </div><div><b>Location</b></div>
196
+ </div>
197
+ <div style="position: absolute; top: 154px; left: 57px; transform: translate(-50%, -50%); text-align: center;">
198
+ <div style="font-size: 2em;">๐Ÿƒ</div><div><b>Actions</b></div>
199
+ </div>
200
+ <div style="position: absolute; top: 321px; left: 112px; transform: translate(-50%, -50%); text-align: center;">
201
+ <div style="font-size: 2em;">๐Ÿง </div><div><b>Thoughts</b></div>
202
+ </div>
203
+ <div style="position: absolute; top: 321px; left: 288px; transform: translate(-50%, -50%); text-align: center;">
204
+ <div style="font-size: 2em;">๐Ÿ˜ฒ</div><div><b>Emotions</b></div>
205
+ </div>
206
+ <div style="position: absolute; top: 154px; left: 343px; transform: translate(-50%, -50%); text-align: center;">
207
+ <div style="font-size: 2em;">๐Ÿ’ฌ</div><div><b>Dialogue</b></div>
208
+ </div>
209
+ </div>
210
+ """
211
+ st.markdown(star_html, unsafe_allow_html=True)
212
+
213
+ if __name__ == "__main__":
214
+ main()