awacke1 commited on
Commit
24b4bc7
·
verified ·
1 Parent(s): ad50edf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +276 -0
app.py ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Brain Game 🧠
2
+
3
+ import streamlit as st
4
+ import zlib
5
+ import base64
6
+ import random
7
+ import pandas as pd
8
+ import plotly.express as px
9
+ from streamlit_ace import st_ace
10
+ import streamlit.components.v1 as components
11
+ import json
12
+
13
+ # Utility functions (compress_text and decompress_text) remain the same
14
+
15
+ # Main Streamlit App
16
+ def main():
17
+ st.set_page_config(layout="wide", page_title="Nietzsche's Philosophical Playground")
18
+ st.title("🧠🎮 Nietzsche's Philosophical Playground: Where Ideas Come to Dance")
19
+
20
+ # Initialize session state for game dynamics
21
+ if 'philosophical_points' not in st.session_state:
22
+ st.session_state.philosophical_points = 0
23
+ if 'unlocked_chapters' not in st.session_state:
24
+ st.session_state.unlocked_chapters = ['nietzsche_influence']
25
+
26
+ # Sidebar for navigation and game stats
27
+ st.sidebar.title("🗺️ Philosophical Journey Map")
28
+ st.sidebar.write(f"💡 Philosophical Points: {st.session_state.philosophical_points}")
29
+
30
+ chapters = {
31
+ "📖 Nietzsche's Influence: Beyond Good and Evil": "nietzsche_influence",
32
+ "✍️ The Art of Aphorism: Nietzsche's Literary Genius": "aphoristic_style",
33
+ "🧩 Deconstructing 'Beyond Good and Evil'": "deconstruct_beyond_good_and_evil",
34
+ "📚 Romantic and Literary Influences on Nietzsche": "romantic_influences",
35
+ "🔎 Right Wing Pathology: A Philosophical Analysis": "right_wing_pathology",
36
+ "🦸 The Hero's Journey: From Myth to Modern Psychology": "hero_myth",
37
+ "🙏 The Death of God and the Call to Adventure": "belief_in_god",
38
+ "📈 Übermensch and Incremental Improvement": "incremental_improvement",
39
+ "❤️ Amor Fati: Love, Acceptance, and Challenge": "love_acceptance_challenge",
40
+ "🔍 Epistemology: Sorting Truth from Manipulation": "sorting_truth_manipulation",
41
+ "🗺️ Nietzschean Concept Network": "topic_model_visualization"
42
+ }
43
+
44
+ for chapter, func_name in chapters.items():
45
+ if func_name in st.session_state.unlocked_chapters:
46
+ st.sidebar.markdown(f"[{chapter}](#{func_name})")
47
+ else:
48
+ st.sidebar.markdown(f"🔒 {chapter}")
49
+
50
+ app_mode = st.sidebar.selectbox("🚀 Choose Your Philosophical Quest",
51
+ [chapter for chapter, func_name in chapters.items()
52
+ if func_name in st.session_state.unlocked_chapters])
53
+
54
+ # Call the corresponding function based on user selection
55
+ globals()[chapters[app_mode]]()
56
+
57
+ # Add the Mermaid topic model visualization
58
+ st.header("🗺️ Nietzschean Concept Network")
59
+ render_mermaid_diagram()
60
+
61
+ def render_mermaid_diagram():
62
+ mermaid_code = """
63
+ graph TD
64
+ A[Nietzsche's Philosophy] --> B[Übermensch]
65
+ A --> C[Eternal Recurrence]
66
+ A --> D[Will to Power]
67
+ B --> E[Self-Overcoming]
68
+ C --> F[Amor Fati]
69
+ D --> G[Master Morality]
70
+ D --> H[Slave Morality]
71
+ A --> I[Death of God]
72
+ I --> J[Revaluation of Values]
73
+ B --> K[Creation of Values]
74
+ F --> L[Embracing Life]
75
+ G --> M[Nobility]
76
+ H --> N[Ressentiment]
77
+ """
78
+
79
+ # Custom CSS to make the diagram interactive
80
+ custom_css = """
81
+ <style>
82
+ .mermaid svg { cursor: pointer; }
83
+ .mermaid .node rect { fill: #f4f4f4; stroke: #999; stroke-width: 1px; }
84
+ .mermaid .node text { fill: #333; }
85
+ .mermaid .edgePath path { stroke: #999; stroke-width: 1px; }
86
+ .mermaid .node:hover rect { fill: #e1e1e1; }
87
+ </style>
88
+ """
89
+
90
+ # JavaScript to add interactivity
91
+ custom_js = """
92
+ <script>
93
+ const svg = document.querySelector(".mermaid svg");
94
+ if (svg) {
95
+ const nodes = svg.querySelectorAll(".node");
96
+ nodes.forEach(node => {
97
+ node.addEventListener("click", function() {
98
+ const rect = this.querySelector("rect");
99
+ const text = this.querySelector("text");
100
+ rect.style.fill = getRandomColor();
101
+ text.style.fontWeight = "bold";
102
+ wiggleNode(this);
103
+ });
104
+ });
105
+ }
106
+
107
+ function getRandomColor() {
108
+ return "#" + Math.floor(Math.random()*16777215).toString(16);
109
+ }
110
+
111
+ function wiggleNode(node) {
112
+ let angle = 0;
113
+ const interval = setInterval(() => {
114
+ angle += 5;
115
+ node.style.transform = `rotate(${Math.sin(angle * Math.PI / 180) * 5}deg)`;
116
+ if (angle >= 360) clearInterval(interval);
117
+ }, 16);
118
+ }
119
+ </script>
120
+ """
121
+
122
+ # Combine Mermaid diagram with custom CSS and JavaScript
123
+ mermaid_html = f"""
124
+ {custom_css}
125
+ <div class="mermaid">
126
+ {mermaid_code}
127
+ </div>
128
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.13.3/mermaid.min.js"></script>
129
+ <script>mermaid.initialize({{startOnLoad:true}});</script>
130
+ {custom_js}
131
+ """
132
+
133
+ components.html(mermaid_html, height=600)
134
+
135
+ def nietzsche_influence():
136
+ st.header("📖 Nietzsche's Influence: Beyond Good and Evil")
137
+
138
+ st.write("""
139
+ Welcome, brave soul, to the whirlwind world of Friedrich Nietzsche!
140
+ Prepare to have your mind twisted, turned, and occasionally tickled
141
+ as we explore the influence of philosophy's most notorious mustache owner. 🎭
142
+ """)
143
+
144
+ # Interactive Nietzsche Quote Generator
145
+ st.subheader("🎲 Roll the Dice of Wisdom")
146
+ if st.button("Generate Nietzschean Insight"):
147
+ quotes = [
148
+ "God is dead! God remains dead! And we have killed him.",
149
+ "He who has a why to live can bear almost any how.",
150
+ "There are no facts, only interpretations.",
151
+ "In heaven, all the interesting people are missing.",
152
+ "What does not kill me makes me stronger.",
153
+ ]
154
+ quote = random.choice(quotes)
155
+ st.info(f"🧠 {quote}")
156
+ st.session_state.philosophical_points += 5
157
+ st.success(f"You gained 5 philosophical points! Total: {st.session_state.philosophical_points}")
158
+
159
+ # Nietzsche's Concept Strength Meter
160
+ st.subheader("💪 Concept Strength Meter")
161
+ concept = st.selectbox("Choose a Nietzschean concept:",
162
+ ["Übermensch", "Eternal Recurrence", "Will to Power", "Master-Slave Morality"])
163
+ strength = random.randint(1, 100)
164
+ st.progress(strength / 100)
165
+ st.write(f"The strength of '{concept}' in today's philosophy: {strength}%")
166
+
167
+ # Philosophical Dilemma Game
168
+ st.subheader("🤔 Philosophical Dilemma Solver")
169
+ dilemma = st.text_input("Present a moral dilemma:")
170
+ if st.button("What Would Nietzsche Do?"):
171
+ responses = [
172
+ "Embrace the chaos and dance!",
173
+ "Create your own values and live by them fiercely.",
174
+ "Consider the perspective of the Übermensch.",
175
+ "Ask yourself: Would you will this to recur eternally?",
176
+ "Reject conventional morality and forge your own path.",
177
+ ]
178
+ nietzsche_response = random.choice(responses)
179
+ st.write(f"Nietzsche might say: {nietzsche_response}")
180
+ st.session_state.philosophical_points += 10
181
+ st.success(f"You gained 10 philosophical points for wrestling with morality! Total: {st.session_state.philosophical_points}")
182
+
183
+ # Unlock new chapter if enough points
184
+ if st.session_state.philosophical_points >= 50 and 'aphoristic_style' not in st.session_state.unlocked_chapters:
185
+ st.session_state.unlocked_chapters.append('aphoristic_style')
186
+ st.balloons()
187
+ st.success("Congratulations! You've unlocked 'The Art of Aphorism' chapter!")
188
+
189
+ def aphoristic_style():
190
+ st.header("✍️ The Art of Aphorism: Nietzsche's Literary Genius")
191
+
192
+ st.write("""
193
+ Welcome to the dojo of philosophical one-liners! Here, we'll master the art of
194
+ saying profound things in tweet-sized chunks. Nietzsche was the OG of philosophical
195
+ mic drops, so let's channel our inner mustachioed madman! 🥋📜
196
+ """)
197
+
198
+ # Aphorism Generator 2.0
199
+ st.subheader("🎭 The Aphorism Forge")
200
+ subjects = ["The wise", "Fools", "Heroes", "Cowards", "Artists", "Scientists"]
201
+ verbs = ["seek", "fear", "embrace", "reject", "transcend", "dance with"]
202
+ objects = ["truth", "power", "love", "death", "life", "eternity"]
203
+ twists = ["but find only mirrors", "yet discover their shadow", "and become what they behold", "only to lose themselves", "and laugh at the absurdity"]
204
+
205
+ if st.button("Forge an Aphorism"):
206
+ aphorism = f"{random.choice(subjects)} {random.choice(verbs)} {random.choice(objects)}, {random.choice(twists)}."
207
+ st.success(f"🧠✍️ {aphorism}")
208
+ st.session_state.philosophical_points += 7
209
+ st.info(f"You gained 7 philosophical points for your aphoristic wisdom! Total: {st.session_state.philosophical_points}")
210
+
211
+ # Aphorism Workshop with Streamlit Ace Editor
212
+ st.subheader("🖋️ Craft Your Magnum Opus")
213
+ st.write("Channel your inner Nietzsche and craft an aphorism that will echo through the ages!")
214
+
215
+ user_aphorism = st_ace(
216
+ placeholder="Type your aphorism here...",
217
+ language="plain_text",
218
+ theme="monokai",
219
+ keybinding="vscode",
220
+ font_size=14,
221
+ min_lines=5,
222
+ key="aphorism_editor"
223
+ )
224
+
225
+ if user_aphorism:
226
+ st.write("Your Aphoristic Gem:")
227
+ st.info(user_aphorism)
228
+ quality_score = random.randint(1, 100)
229
+ st.write(f"Nietzsche's Ghost rates your aphorism: {quality_score}/100")
230
+ if quality_score > 80:
231
+ st.success("Bravo! Nietzsche would be proud (and slightly jealous).")
232
+ st.session_state.philosophical_points += 20
233
+ st.success(f"You gained 20 philosophical points for your brilliant aphorism! Total: {st.session_state.philosophical_points}")
234
+ elif quality_score > 50:
235
+ st.warning("Not bad! Keep refining your philosophical wit.")
236
+ st.session_state.philosophical_points += 10
237
+ st.info(f"You gained 10 philosophical points for your decent attempt! Total: {st.session_state.philosophical_points}")
238
+ else:
239
+ st.error("Nietzsche suggests more contemplation... perhaps on a mountain top?")
240
+ st.session_state.philosophical_points += 5
241
+ st.info(f"You gained 5 philosophical points for effort! Total: {st.session_state.philosophical_points}")
242
+
243
+ # Unlock new chapter if enough points
244
+ if st.session_state.philosophical_points >= 100 and 'deconstruct_beyond_good_and_evil' not in st.session_state.unlocked_chapters:
245
+ st.session_state.unlocked_chapters.append('deconstruct_beyond_good_and_evil')
246
+ st.balloons()
247
+ st.success("Congratulations! You've unlocked the 'Deconstructing Beyond Good and Evil' chapter!")
248
+
249
+ # Additional chapter functions would be defined here...
250
+
251
+ def topic_model_visualization():
252
+ st.header("🗺️ Nietzschean Concept Network")
253
+ render_mermaid_diagram()
254
+
255
+ # File handling functions
256
+ def save_file(content, filename):
257
+ st.download_button(
258
+ label="Download File",
259
+ data=content,
260
+ file_name=filename,
261
+ mime="text/plain"
262
+ )
263
+
264
+ def load_file():
265
+ uploaded_file = st.file_uploader("Choose a file")
266
+ if uploaded_file is not None:
267
+ content = uploaded_file.getvalue().decode("utf-8")
268
+ return content
269
+ return None
270
+
271
+ # Main function to run the Streamlit app
272
+ if __name__ == "__main__":
273
+ main()
274
+
275
+
276
+