# Brain Game 🧠
import streamlit as st
import zlib
import base64
import random
import pandas as pd
import plotly.express as px
from streamlit_ace import st_ace
import streamlit.components.v1 as components
import json
# Utility functions (compress_text and decompress_text) remain the same
# Main Streamlit App
def main():
st.set_page_config(layout="wide", page_title="Nietzsche's Philosophical Playground")
st.title("🧠🎮 Nietzsche's Philosophical Playground: Where Ideas Come to Dance")
# Initialize session state for game dynamics
if 'philosophical_points' not in st.session_state:
st.session_state.philosophical_points = 0
if 'unlocked_chapters' not in st.session_state:
st.session_state.unlocked_chapters = ['nietzsche_influence']
# Sidebar for navigation and game stats
st.sidebar.title("🗺️ Philosophical Journey Map")
st.sidebar.write(f"💡 Philosophical Points: {st.session_state.philosophical_points}")
chapters = {
"📖 Nietzsche's Influence: Beyond Good and Evil": "nietzsche_influence",
"✍️ The Art of Aphorism: Nietzsche's Literary Genius": "aphoristic_style",
"🧩 Deconstructing 'Beyond Good and Evil'": "deconstruct_beyond_good_and_evil",
"📚 Romantic and Literary Influences on Nietzsche": "romantic_influences",
"🔎 Right Wing Pathology: A Philosophical Analysis": "right_wing_pathology",
"🦸 The Hero's Journey: From Myth to Modern Psychology": "hero_myth",
"🙏 The Death of God and the Call to Adventure": "belief_in_god",
"📈 Übermensch and Incremental Improvement": "incremental_improvement",
"❤️ Amor Fati: Love, Acceptance, and Challenge": "love_acceptance_challenge",
"🔍 Epistemology: Sorting Truth from Manipulation": "sorting_truth_manipulation",
"🗺️ Nietzschean Concept Network": "topic_model_visualization"
}
for chapter, func_name in chapters.items():
if func_name in st.session_state.unlocked_chapters:
st.sidebar.markdown(f"[{chapter}](#{func_name})")
else:
st.sidebar.markdown(f"🔒 {chapter}")
app_mode = st.sidebar.selectbox("🚀 Choose Your Philosophical Quest",
[chapter for chapter, func_name in chapters.items()
if func_name in st.session_state.unlocked_chapters])
# Call the corresponding function based on user selection
globals()[chapters[app_mode]]()
# Add the Mermaid topic model visualization
st.header("🗺️ Nietzschean Concept Network")
render_mermaid_diagram()
def render_mermaid_diagram():
mermaid_code = """
graph TD
A[Nietzsche's Philosophy] --> B[Übermensch]
A --> C[Eternal Recurrence]
A --> D[Will to Power]
B --> E[Self-Overcoming]
C --> F[Amor Fati]
D --> G[Master Morality]
D --> H[Slave Morality]
A --> I[Death of God]
I --> J[Revaluation of Values]
B --> K[Creation of Values]
F --> L[Embracing Life]
G --> M[Nobility]
H --> N[Ressentiment]
"""
# Custom CSS to make the diagram interactive
custom_css = """
"""
# JavaScript to add interactivity
custom_js = """
"""
# Combine Mermaid diagram with custom CSS and JavaScript
mermaid_html = f"""
{custom_css}
{mermaid_code}
{custom_js}
"""
components.html(mermaid_html, height=600)
def nietzsche_influence():
st.header("📖 Nietzsche's Influence: Beyond Good and Evil")
st.write("""
Welcome, brave soul, to the whirlwind world of Friedrich Nietzsche!
Prepare to have your mind twisted, turned, and occasionally tickled
as we explore the influence of philosophy's most notorious mustache owner. 🎭
""")
# Interactive Nietzsche Quote Generator
st.subheader("🎲 Roll the Dice of Wisdom")
if st.button("Generate Nietzschean Insight"):
quotes = [
"God is dead! God remains dead! And we have killed him.",
"He who has a why to live can bear almost any how.",
"There are no facts, only interpretations.",
"In heaven, all the interesting people are missing.",
"What does not kill me makes me stronger.",
]
quote = random.choice(quotes)
st.info(f"🧠 {quote}")
st.session_state.philosophical_points += 5
st.success(f"You gained 5 philosophical points! Total: {st.session_state.philosophical_points}")
# Nietzsche's Concept Strength Meter
st.subheader("💪 Concept Strength Meter")
concept = st.selectbox("Choose a Nietzschean concept:",
["Übermensch", "Eternal Recurrence", "Will to Power", "Master-Slave Morality"])
strength = random.randint(1, 100)
st.progress(strength / 100)
st.write(f"The strength of '{concept}' in today's philosophy: {strength}%")
# Philosophical Dilemma Game
st.subheader("🤔 Philosophical Dilemma Solver")
dilemma = st.text_input("Present a moral dilemma:")
if st.button("What Would Nietzsche Do?"):
responses = [
"Embrace the chaos and dance!",
"Create your own values and live by them fiercely.",
"Consider the perspective of the Übermensch.",
"Ask yourself: Would you will this to recur eternally?",
"Reject conventional morality and forge your own path.",
]
nietzsche_response = random.choice(responses)
st.write(f"Nietzsche might say: {nietzsche_response}")
st.session_state.philosophical_points += 10
st.success(f"You gained 10 philosophical points for wrestling with morality! Total: {st.session_state.philosophical_points}")
# Unlock new chapter if enough points
if st.session_state.philosophical_points >= 50 and 'aphoristic_style' not in st.session_state.unlocked_chapters:
st.session_state.unlocked_chapters.append('aphoristic_style')
st.balloons()
st.success("Congratulations! You've unlocked 'The Art of Aphorism' chapter!")
def aphoristic_style():
st.header("✍️ The Art of Aphorism: Nietzsche's Literary Genius")
st.write("""
Welcome to the dojo of philosophical one-liners! Here, we'll master the art of
saying profound things in tweet-sized chunks. Nietzsche was the OG of philosophical
mic drops, so let's channel our inner mustachioed madman! 🥋📜
""")
# Aphorism Generator 2.0
st.subheader("🎭 The Aphorism Forge")
subjects = ["The wise", "Fools", "Heroes", "Cowards", "Artists", "Scientists"]
verbs = ["seek", "fear", "embrace", "reject", "transcend", "dance with"]
objects = ["truth", "power", "love", "death", "life", "eternity"]
twists = ["but find only mirrors", "yet discover their shadow", "and become what they behold", "only to lose themselves", "and laugh at the absurdity"]
if st.button("Forge an Aphorism"):
aphorism = f"{random.choice(subjects)} {random.choice(verbs)} {random.choice(objects)}, {random.choice(twists)}."
st.success(f"🧠✍️ {aphorism}")
st.session_state.philosophical_points += 7
st.info(f"You gained 7 philosophical points for your aphoristic wisdom! Total: {st.session_state.philosophical_points}")
# Aphorism Workshop with Streamlit Ace Editor
st.subheader("🖋️ Craft Your Magnum Opus")
st.write("Channel your inner Nietzsche and craft an aphorism that will echo through the ages!")
user_aphorism = st_ace(
placeholder="Type your aphorism here...",
language="plain_text",
theme="monokai",
keybinding="vscode",
font_size=14,
min_lines=5,
key="aphorism_editor"
)
if user_aphorism:
st.write("Your Aphoristic Gem:")
st.info(user_aphorism)
quality_score = random.randint(1, 100)
st.write(f"Nietzsche's Ghost rates your aphorism: {quality_score}/100")
if quality_score > 80:
st.success("Bravo! Nietzsche would be proud (and slightly jealous).")
st.session_state.philosophical_points += 20
st.success(f"You gained 20 philosophical points for your brilliant aphorism! Total: {st.session_state.philosophical_points}")
elif quality_score > 50:
st.warning("Not bad! Keep refining your philosophical wit.")
st.session_state.philosophical_points += 10
st.info(f"You gained 10 philosophical points for your decent attempt! Total: {st.session_state.philosophical_points}")
else:
st.error("Nietzsche suggests more contemplation... perhaps on a mountain top?")
st.session_state.philosophical_points += 5
st.info(f"You gained 5 philosophical points for effort! Total: {st.session_state.philosophical_points}")
# Unlock new chapter if enough points
if st.session_state.philosophical_points >= 100 and 'deconstruct_beyond_good_and_evil' not in st.session_state.unlocked_chapters:
st.session_state.unlocked_chapters.append('deconstruct_beyond_good_and_evil')
st.balloons()
st.success("Congratulations! You've unlocked the 'Deconstructing Beyond Good and Evil' chapter!")
# Additional chapter functions would be defined here...
def topic_model_visualization():
st.header("🗺️ Nietzschean Concept Network")
render_mermaid_diagram()
# File handling functions
def save_file(content, filename):
st.download_button(
label="Download File",
data=content,
file_name=filename,
mime="text/plain"
)
def load_file():
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
content = uploaded_file.getvalue().decode("utf-8")
return content
return None
# Main function to run the Streamlit app
if __name__ == "__main__":
main()