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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Set page configuration with a title and favicon
|
| 7 |
+
st.set_page_config(page_title="🌌🚀 Transhuman Space Encyclopedia", page_icon="🌠", layout="wide")
|
| 8 |
+
|
| 9 |
+
# Ensure the directory for storing scores exists
|
| 10 |
+
score_dir = "scores"
|
| 11 |
+
os.makedirs(score_dir, exist_ok=True)
|
| 12 |
+
|
| 13 |
+
# Function to generate a unique key for each button, including an emoji
|
| 14 |
+
def generate_key(label, header, idx):
|
| 15 |
+
return f"{header}_{label}_{idx}_key"
|
| 16 |
+
|
| 17 |
+
# Function to increment and save score
|
| 18 |
+
def update_score(key, increment=1):
|
| 19 |
+
score_file = os.path.join(score_dir, f"{key}.json")
|
| 20 |
+
if os.path.exists(score_file):
|
| 21 |
+
with open(score_file, "r") as file:
|
| 22 |
+
score_data = json.load(file)
|
| 23 |
+
else:
|
| 24 |
+
score_data = {"clicks": 0, "score": 0}
|
| 25 |
+
|
| 26 |
+
score_data["clicks"] += 1
|
| 27 |
+
score_data["score"] += increment
|
| 28 |
+
|
| 29 |
+
with open(score_file, "w") as file:
|
| 30 |
+
json.dump(score_data, file)
|
| 31 |
+
|
| 32 |
+
return score_data["score"]
|
| 33 |
+
|
| 34 |
+
# Function to load score
|
| 35 |
+
def load_score(key):
|
| 36 |
+
score_file = os.path.join(score_dir, f"{key}.json")
|
| 37 |
+
if os.path.exists(score_file):
|
| 38 |
+
with open(score_file, "r") as file:
|
| 39 |
+
score_data = json.load(file)
|
| 40 |
+
return score_data["score"]
|
| 41 |
+
return 0
|
| 42 |
+
|
| 43 |
+
# Transhuman Space glossary with full content
|
| 44 |
+
transhuman_glossary = {
|
| 45 |
+
"🚀 Core Technologies": ["Nanotechnology🔬", "Artificial Intelligence🤖", "Quantum Computing💻", "Spacecraft Engineering🛸", "Biotechnology🧬", "Cybernetics🦾", "Virtual Reality🕶️", "Energy Systems⚡", "Material Science🧪", "Communication Technologies📡"],
|
| 46 |
+
"🌐 Nations": ["Terran Federation🌍", "Martian Syndicate🔴", "Jovian Republics🪐", "Asteroid Belt Communities🌌", "Venusian Colonies🌋", "Lunar States🌖", "Outer System Alliances✨", "Digital Consciousness Collectives🧠", "Transhumanist Enclaves🦿", "Non-Human Intelligence Tribes👽"],
|
| 47 |
+
"💡 Memes": ["Post-Humanism🚶♂️➡️🚀", "Neo-Evolutionism🧬📈", "Digital Ascendancy💾👑", "Solar System Nationalism🌞🏛", "Space Explorationism🚀🛰", "Cyber Democracy🖥️🗳️", "Interstellar Environmentalism🌍💚", "Quantum Mysticism🔮💫", "Techno-Anarchism🔌🏴", "Cosmic Preservationism🌌🛡️"],
|
| 48 |
+
"🏛 Institutions": ["Interstellar Council🪖", "Transhuman Ethical Standards Organization📜", "Galactic Trade Union🤝", "Space Habitat Authority🏠", "Artificial Intelligence Safety Commission🤖🔒", "Extraterrestrial Relations Board👽🤝", "Quantum Research Institute🔬", "Biogenetics Oversight Committee🧫", "Cyberspace Regulatory Agency💻", "Planetary Defense Coalition🌍🛡"],
|
| 49 |
+
"🔗 Organizations": ["Neural Network Pioneers🧠🌐", "Spacecraft Innovators Guild🚀🛠", "Quantum Computing Consortium💻🔗", "Interplanetary Miners Union⛏️🪐", "Cybernetic Augmentation Advocates🦾❤️", "Biotechnological Harmony Group🧬🕊", "Stellar Navigation Circle🧭✨", "Virtual Reality Creators Syndicate🕶️🎨", "Renewable Energy Pioneers⚡🌱", "Transhuman Rights Activists🦿📢"],
|
| 50 |
+
"⚔️ War": ["Space Warfare Tactics🚀⚔️", "Cyber Warfare🖥️🔒", "Biological Warfare🧬💣", "Nanotech Warfare🔬⚔️", "Psychological Operations🧠🗣️", "Quantum Encryption & Decryption🔐💻", "Kinetic Bombardment🚀💥", "Energy Shield Defense🛡️⚡", "Stealth Spacecraft🚀🔇", "Artificial Intelligence Combat🤖⚔️"],
|
| 51 |
+
"🎖 Military": ["Interstellar Navy🚀🎖", "Planetary Guard🌍🛡", "Cybernetic Marines🦾🔫", "Nanotech Soldiers🔬💂", "Space Drone Fleet🛸🤖", "Quantum Signal Corps💻📡", "Special Operations Forces👥⚔️", "Artificial Intelligence Strategists🤖🗺️", "Orbital Defense Systems🌌🛡️", "Exoskeleton Brigades🦾🚶♂️"],
|
| 52 |
+
"🦹 Outlaws": ["Pirate Fleets🏴☠️🚀", "Hacktivist Collectives💻🚫", "Smuggler Caravans🛸💼", "Rebel AI Entities🤖🚩", "Black Market Biotech Dealers🧬💰", "Quantum Thieves💻🕵️♂️", "Space Nomad Raiders🚀🏴☠️", "Cyberspace Intruders💻👾", "Anti-Transhumanist Factions🚫🦾", "Rogue Nanotech Swarms🔬🦠"],
|
| 53 |
+
"👽 Terrorists": ["Bioengineered Virus Spreaders🧬💉", "Nanotechnology Saboteurs🔬🧨", "Cyber Terrorist Networks💻🔥", "Rogue AI Sects🤖🛑", "Space Anarchist Cells🚀Ⓐ", "Quantum Data Hijackers💻🔓", "Environmental Extremists🌍💣", "Technological Singularity Cults🤖🙏", "Interspecies Supremacists👽👑", "Orbital Bombardment Threats🛰️💥"],
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Function to search glossary and display results
|
| 58 |
+
def search_glossary(query):
|
| 59 |
+
for category, terms in transhuman_glossary.items():
|
| 60 |
+
if query.lower() in (term.lower() for term in terms):
|
| 61 |
+
st.markdown(f"### {category}")
|
| 62 |
+
st.write(f"- {query}")
|
| 63 |
+
|
| 64 |
+
# Display instructions and handle query parameters
|
| 65 |
+
st.markdown("## Glossary Lookup\nEnter a term in the URL query, like `?q=Nanotechnology` or `?query=Martian Syndicate`.")
|
| 66 |
+
query_params = st.query_params
|
| 67 |
+
query = (query_params.get('q') or query_params.get('query') or [''])[0]
|
| 68 |
+
if query: search_glossary(query)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# Display the glossary with Streamlit components, ensuring emojis are used
|
| 73 |
+
def display_glossary(area):
|
| 74 |
+
st.subheader(f"📘 Glossary for {area}")
|
| 75 |
+
terms = transhuman_glossary[area]
|
| 76 |
+
for idx, term in enumerate(terms, start=1):
|
| 77 |
+
st.write(f"{idx}. {term}")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# Function to display glossary in a 3x3 grid
|
| 81 |
+
def display_glossary_grid(glossary):
|
| 82 |
+
# Group related categories for a 3x3 grid
|
| 83 |
+
groupings = [
|
| 84 |
+
["🚀 Core Technologies", "🌐 Nations", "💡 Memes"],
|
| 85 |
+
["🏛 Institutions", "🔗 Organizations", "⚔️ War"],
|
| 86 |
+
["🎖 Military", "🦹 Outlaws", "👽 Terrorists"],
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
for group in groupings:
|
| 90 |
+
cols = st.columns(3) # Create three columns
|
| 91 |
+
for idx, category in enumerate(group):
|
| 92 |
+
with cols[idx]:
|
| 93 |
+
st.markdown(f"### {category}")
|
| 94 |
+
terms = glossary[category]
|
| 95 |
+
for term in terms:
|
| 96 |
+
st.write(f"- {term}")
|
| 97 |
+
|
| 98 |
+
# Display the glossary grid
|
| 99 |
+
st.title("Transhuman Space Glossary 🌌")
|
| 100 |
+
display_glossary_grid(transhuman_glossary)
|
| 101 |
+
|
| 102 |
+
# Streamlined UI for displaying buttons with scores, integrating emojis
|
| 103 |
+
def display_buttons_with_scores():
|
| 104 |
+
for header, terms in transhuman_glossary.items():
|
| 105 |
+
st.markdown(f"## {header}")
|
| 106 |
+
for term in terms:
|
| 107 |
+
key = generate_key(term, header, terms.index(term))
|
| 108 |
+
score = load_score(key)
|
| 109 |
+
if st.button(f"{term} {score}🚀", key=key):
|
| 110 |
+
update_score(key)
|
| 111 |
+
st.experimental_rerun()
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
st.title("🌌🚀 Transhuman Space Encyclopedia")
|
| 115 |
+
st.markdown("## Explore the universe of Transhuman Space through interactive storytelling and encyclopedic knowledge.🌠")
|
| 116 |
+
display_buttons_with_scores()
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def fetch_wikipedia_summary(keyword):
|
| 124 |
+
# Placeholder function for fetching Wikipedia summaries
|
| 125 |
+
# In a real app, you might use requests to fetch from the Wikipedia API
|
| 126 |
+
return f"Summary for {keyword}. For more information, visit Wikipedia."
|
| 127 |
+
|
| 128 |
+
def create_search_url_youtube(keyword):
|
| 129 |
+
base_url = "https://www.youtube.com/results?search_query="
|
| 130 |
+
return base_url + keyword.replace(' ', '+')
|
| 131 |
+
|
| 132 |
+
def create_search_url_bing(keyword):
|
| 133 |
+
base_url = "https://www.bing.com/search?q="
|
| 134 |
+
return base_url + keyword.replace(' ', '+')
|
| 135 |
+
|
| 136 |
+
def create_search_url_wikipedia(keyword):
|
| 137 |
+
base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
|
| 138 |
+
return base_url + keyword.replace(' ', '+')
|
| 139 |
+
|
| 140 |
+
def create_search_url_google(keyword):
|
| 141 |
+
base_url = "https://www.google.com/search?q="
|
| 142 |
+
return base_url + keyword.replace(' ', '+')
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def display_images_and_wikipedia_summaries():
|
| 146 |
+
st.title('Gallery with Related Stories')
|
| 147 |
+
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
| 148 |
+
if not image_files:
|
| 149 |
+
st.write("No PNG images found in the current directory.")
|
| 150 |
+
return
|
| 151 |
+
|
| 152 |
+
for image_file in image_files:
|
| 153 |
+
image = Image.open(image_file)
|
| 154 |
+
st.image(image, caption=image_file, use_column_width=True)
|
| 155 |
+
|
| 156 |
+
keyword = image_file.split('.')[0] # Assumes keyword is the file name without extension
|
| 157 |
+
|
| 158 |
+
# Display Wikipedia and Google search links
|
| 159 |
+
wikipedia_url = create_search_url_wikipedia(keyword)
|
| 160 |
+
google_url = create_search_url_google(keyword)
|
| 161 |
+
youtube_url = create_search_url_youtube(keyword)
|
| 162 |
+
bing_url = create_search_url_bing(keyword)
|
| 163 |
+
|
| 164 |
+
links_md = f"""
|
| 165 |
+
[Wikipedia]({wikipedia_url}) |
|
| 166 |
+
[Google]({google_url}) |
|
| 167 |
+
[YouTube]({youtube_url}) |
|
| 168 |
+
[Bing]({bing_url})
|
| 169 |
+
"""
|
| 170 |
+
st.markdown(links_md)
|
| 171 |
+
|
| 172 |
+
display_images_and_wikipedia_summaries()
|
| 173 |
+
|
| 174 |
+
def get_all_query_params(key):
|
| 175 |
+
return st.query_params().get(key, [])
|
| 176 |
+
|
| 177 |
+
def clear_query_params():
|
| 178 |
+
st.query_params()
|
| 179 |
+
|
| 180 |
+
# Assuming the transhuman_glossary and other setup code remains the same
|
| 181 |
+
|
| 182 |
+
# Function to display content or image based on a query
|
| 183 |
+
def display_content_or_image(query):
|
| 184 |
+
# Check if the query matches any glossary term
|
| 185 |
+
for category, terms in transhuman_glossary.items():
|
| 186 |
+
for term in terms:
|
| 187 |
+
if query.lower() in term.lower():
|
| 188 |
+
st.subheader(f"Found in {category}:")
|
| 189 |
+
st.write(term)
|
| 190 |
+
return True # Return after finding and displaying the first match
|
| 191 |
+
|
| 192 |
+
# Check for an image match in a predefined directory (adjust path as needed)
|
| 193 |
+
image_dir = "images" # Example directory where images are stored
|
| 194 |
+
image_path = f"{image_dir}/{query}.png" # Construct image path with query
|
| 195 |
+
if os.path.exists(image_path):
|
| 196 |
+
st.image(image_path, caption=f"Image for {query}")
|
| 197 |
+
return True
|
| 198 |
+
|
| 199 |
+
# If no content or image is found
|
| 200 |
+
st.warning("No matching content or image found.")
|
| 201 |
+
return False
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
st.write("Current Query Parameters:", st.query_params)
|
| 207 |
+
st.markdown("### Query Parameters - These Deep Link Map to Remixable Methods, Navigate or Trigger Functionalities")
|
| 208 |
+
|
| 209 |
+
# Example: Using query parameters to navigate or trigger functionalities
|
| 210 |
+
if 'action' in st.query_params:
|
| 211 |
+
action = st.query_params()['action'][0] # Get the first (or only) 'action' parameter
|
| 212 |
+
if action == 'show_message':
|
| 213 |
+
st.success("Showing a message because 'action=show_message' was found in the URL.")
|
| 214 |
+
elif action == 'clear':
|
| 215 |
+
clear_query_params()
|
| 216 |
+
st.experimental_rerun()
|
| 217 |
+
|
| 218 |
+
# Handling repeated keys
|
| 219 |
+
if 'multi' in st.query_params:
|
| 220 |
+
multi_values = get_all_query_params('multi')
|
| 221 |
+
st.write("Values for 'multi':", multi_values)
|
| 222 |
+
|
| 223 |
+
# Manual entry for demonstration
|
| 224 |
+
st.write("Enter query parameters in the URL like this: ?action=show_message&multi=1&multi=2")
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
if 'query' in st.query_params:
|
| 230 |
+
query = st.query_params['query'][0] # Get the query parameter
|
| 231 |
+
# Display content or image based on the query
|
| 232 |
+
display_content_or_image(query)
|
| 233 |
+
|
| 234 |
+
# Add a clear query parameters button for convenience
|
| 235 |
+
if st.button("Clear Query Parameters", key='ClearQueryParams'):
|
| 236 |
+
# This will clear the browser URL's query parameters
|
| 237 |
+
st.experimental_set_query_params
|
| 238 |
+
st.experimental_rerun()
|
| 239 |
+
|