Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| from datetime import datetime | |
| # --- 1. DATA STRUCTURE FOR BioDS CONTENT --- | |
| SPACE_DATA = { | |
| "MilkyWayGalaxy": { | |
| "title": "Milky Way Galaxy: Local Celestial Bodies & Stars", | |
| "items": [ | |
| {"id": "MW_JUPITER", "name": "Jupiter Planet", "color": "0xDDAA00", "detail": "Giant gas planet. Key focus in astrobiology for its moon Europa. Its massive radiation belts make life challenging. Features complex atmospheric biology models.", | |
| "health_pct": 85, "moons": 95, "direction": "North-East Ecliptic", "surface": "Gaseous/Icy", "air_index": "N/A (Gas Giant)", "human_like": "None", "perplexity": 0.98}, | |
| {"id": "MW_SATURN", "name": "Saturn Moon Titan", "color": "0xAAAAFF", "detail": "Titan has a dense atmosphere and stable liquid methane on its surface. Considered highly promising for exotic life forms, utilizing non-water solvents.", | |
| "health_pct": 92, "moons": 0, "direction": "South Celestial Pole", "surface": "Icy/Liquid Methane", "air_index": "High Methane/Nitrogen", "human_like": "Low Probability", "perplexity": 0.95}, | |
| {"id": "MW_ORION", "name": "Orion Nebula (M42)", "color": "0xFF5555", "detail": "Massive star formation region, a cosmic lab for pre-biotic chemistry. Intense UV radiation shapes the biology of dust grains and molecular clouds.", | |
| "health_pct": 78, "moons": "N/A", "direction": "Galactic Center", "surface": "Gas/Dust Cloud", "air_index": "Molecular Hydrogen", "human_like": "Zero", "perplexity": 0.88}, | |
| {"id": "MW_SUN", "name": "The Sun (G2V Star)", "color": "0xFFFF55", "detail": "Our star, the ultimate source of energy for terrestrial life. Its habitable zone is the core region for Earth-based biology. Future research focuses on solar flare resilience.", | |
| "health_pct": 99, "moons": "N/A", "direction": "Sol Centerpoint", "surface": "Plasma", "air_index": "Hydrogen/Helium", "human_like": "Zero", "perplexity": 0.99}, | |
| {"id": "MW_EARTH", "name": "Earth's Biosphere", "color": "0x00FF00", "detail": "A control point for all space biology: the only known planet to harbor life. Its complex ecosystem is a benchmark for evaluating life signatures elsewhere.", | |
| "health_pct": 65, "moons": 1, "direction": "Local Arm Segment", "surface": "Solid/Liquid Water", "air_index": "Excellent (N2/O2)", "human_like": "Benchmark", "perplexity": 0.65}, | |
| {"id": "MW_MARS", "name": "Mars Planet (Terraforming)", "color": "0xFF5500", "detail": "A prime target for terraforming and searching for past microbial life. Current biology focuses on permafrost extremophiles and atmospheric oxygenation projects.", | |
| "health_pct": 75, "moons": 2, "direction": "Inner Solar System", "surface": "Rocky (Iron Oxide)", "air_index": "High CO2", "human_like": "Low, potential for settlement", "perplexity": 0.70}, | |
| {"id": "MW_VENUS", "name": "Venus Atmosphere", "color": "0xFF88CC", "detail": "A highly acidic and hot surface, but the upper atmosphere is temperate. Hypothesized cloud-based extremophile life forms utilizing sulfur compounds are a key research topic.", | |
| "health_pct": 55, "moons": 0, "direction": "Inner Solar System", "surface": "Molten/Volcanic", "air_index": "Sulfuric Acid/CO2", "human_like": "Zero", "perplexity": 0.85}, | |
| {"id": "MW_URANUS", "name": "Uranus Ice Giant", "color": "0x00AAFF", "detail": "An ice giant with a complex, cold atmosphere. Its unique axial tilt presents challenges for modeling internal heat and potential deep-atmospheric biological zones.", | |
| "health_pct": 82, "moons": 27, "direction": "Outer Solar System", "surface": "Gas/Ice", "air_index": "Hydrogen/Helium/Methane", "human_like": "None", "perplexity": 0.90}, | |
| {"id": "MW_NEPTUNE", "name": "Neptune Triton Moon", "color": "0x0055FF", "detail": "Neptune's largest moon, Triton, is geologically active with cryovolcanoes. Subsurface liquid nitrogen or water oceans make it a candidate for exotic subsurface life.", | |
| "health_pct": 88, "moons": 14, "direction": "Outer Solar System", "surface": "Nitrogen Ice", "air_index": "Trace Nitrogen/Methane", "human_like": "Extremophiles", "perplexity": 0.93}, | |
| {"id": "MW_ALPHACEN", "name": "Alpha Centauri A", "color": "0xFFFF00", "detail": "The nearest star system. Centauri A is a G-type star, similar to the Sun, making its habitable zone a high-priority target for exoplanetary exploration.", | |
| "health_pct": 94, "moons": "Unknown", "direction": "Proxima Vicinity", "surface": "Plasma", "air_index": "Hydrogen/Helium", "human_like": "Medium Probability", "perplexity": 0.75}, | |
| {"id": "MW_BETELG", "name": "Betelgeuse (Red Supergiant)", "color": "0xFF0000", "detail": "A massive, dying star. Its current instability and eventual supernova will sterilize a vast volume of space, but its outer regions currently host dense dust clouds for chemistry.", | |
| "health_pct": 20, "moons": "N/A", "direction": "Orion Constellation", "surface": "Supergiant Plasma", "air_index": "Heavy Elements", "human_like": "Zero", "perplexity": 0.99}, | |
| {"id": "MW_TRAPPIST", "name": "TRAPPIST-1 System", "color": "0xAA00FF", "detail": "A system of seven Earth-sized planets orbiting an ultra-cool dwarf star. Multiple planets are within the theoretical habitable zone, making it a primary focus for atmospheric analysis.", | |
| "health_pct": 85, "moons": "Varies", "direction": "Aquarius Constellation", "surface": "Rocky/Water-World", "air_index": "Complex, analyzing", "human_like": "High Probability", "perplexity": 0.60}, | |
| ] | |
| }, | |
| "AndromedaGalaxy": { | |
| "title": "Andromeda Galaxy (M31): Neighboring Mysteries", | |
| "items": [ | |
| {"id": "AND_CORE", "name": "Andromeda Core Region", "color": "0xFFFFFF", "detail": "A dense, high-metallicity environment with rapid star birth. High stellar density increases the chances of close-proximity gravitational events, impacting planetary stability.", | |
| "health_pct": 70, "moons": "Unknown", "direction": "Approaching MW", "surface": "Dense Stellar", "air_index": "Very Low", "human_like": "Very Low", "perplexity": 0.93}, | |
| {"id": "AND_HALO", "name": "Dark Matter Halo Density", "color": "0x555555", "detail": "The invisible gravitational structure. Interaction between dark matter and regular matter is theorized to influence planetary thermal gradients and internal heat.", | |
| "health_pct": 50, "moons": "N/A", "direction": "Perpendicular Spin", "surface": "Non-Baryonic", "air_index": "Vacuum", "human_like": "Zero", "perplexity": 0.99}, | |
| {"id": "AND_CANDIDATE_P", "name": "Candidate Exoplanet System", "color": "0xAAFFFF", "detail": "Hypothetical system in M31's spiral arms. Search for radio signals (SETI) from Andromeda is ongoing, providing key data points for non-local biology.", | |
| "health_pct": 88, "moons": 4, "direction": "M31 Outer Arm", "surface": "Rocky/Super-Earth", "air_index": "Argon/CO2", "human_like": "Possible", "perplexity": 0.77}, | |
| ] | |
| }, | |
| "Interstellar": { | |
| "title": "Interstellar Medium & Boundary Layers", | |
| "items": [ | |
| {"id": "INT_OORT", "name": "Oort Cloud", "color": "0x00AAFF", "detail": "The most distant region of our Solar System, a reservoir of comets. Contains pristine biological precursors (ices, hydrocarbons) crucial for studying panspermia theories.", | |
| "health_pct": 80, "moons": "N/A", "direction": "Solar System Edge", "surface": "Water Ice/Rock", "air_index": "Vacuum", "human_like": "Zero", "perplexity": 0.96}, | |
| {"id": "INT_KUIPER", "name": "Kuiper Belt Objects", "color": "0x55FFAA", "detail": "Region beyond Neptune, home to dwarf planets and small bodies. Its objects (like Pluto) show cryovolcanism, suggesting subsurface oceans—potential habitats for extremophiles.", | |
| "health_pct": 90, "moons": "Varies", "direction": "Ecliptic Plane", "surface": "Methane/Nitrogen Ice", "air_index": "Trace Methane", "human_like": "Extremophiles", "perplexity": 0.89}, | |
| {"id": "INT_MEDIUM", "name": "Interstellar Medium (ISM)", "color": "0xAA55FF", "detail": "The gas and dust between star systems. Site of complex molecule synthesis, including amino acids, which are then delivered to protoplanetary disks.", | |
| "health_pct": 75, "moons": "N/A", "direction": "Between Stars", "surface": "Atomic Gas/Dust", "air_index": "Atomic/Molecular H", "human_like": "Zero", "perplexity": 0.92}, | |
| {"id": "INT_HELIO", "name": "Heliopause Boundary", "color": "0xCCCCFF", "detail": "The magnetic boundary where the solar wind meets the interstellar medium. This shield protects the solar system's inner biology from the majority of galactic cosmic rays.", | |
| "health_pct": 98, "moons": "N/A", "direction": "Outbound Velocity Vector", "surface": "Plasma/Magnetic Field", "air_index": "Very Low Density", "human_like": "Indirect Shielding", "perplexity": 0.97}, | |
| ] | |
| }, | |
| "OtherGalaxies": { | |
| "title": "Other Galaxies: Diverse Cosmic Habitats", | |
| "items": [ | |
| {"id": "OG_TRIANGULUM", "name": "Triangulum Galaxy (M33)", "color": "0xFF00AA", "detail": "The third largest galaxy in the Local Group. High rate of star formation, leading to a younger population of potentially habitable exoplanets.", | |
| "health_pct": 88, "moons": "Unknown", "direction": "Local Group Edge", "surface": "Spiral Arms", "air_index": "High Star Gas", "human_like": "Medium", "perplexity": 0.70}, | |
| {"id": "OG_WHIRLPOOL", "name": "Whirlpool Galaxy (M51)", "color": "0xAAFF00", "detail": "A classic interacting spiral galaxy. Merging creates shockwaves and intense compression, triggering stellar explosions that sterilize local star systems.", | |
| "health_pct": 68, "moons": "Unknown", "direction": "Interacting", "surface": "Dense Dust", "air_index": "Low", "human_like": "Low", "perplexity": 0.95}, | |
| {"id": "OG_CARTWHEEL", "name": "Cartwheel Galaxy", "color": "0x00FFAA", "detail": "A lenticular galaxy that was ringed by a high-speed collision. The expanding ring is a transient region of intense star birth and high-energy events.", | |
| "health_pct": 72, "moons": "Unknown", "direction": "Expanding Ring", "surface": "High Energy", "air_index": "Ionized Gas", "human_like": "Very Low", "perplexity": 0.90}, | |
| ] | |
| }, | |
| "BlackHoles": { | |
| "title": "Black Holes: Gravity's Biological Frontiers", | |
| "items": [ | |
| {"id": "BH_SAG_A", "name": "Sagittarius A* (Supermassive)", "color": "0xFF8888", "detail": "The supermassive black hole at the center of our galaxy. Its radiation effects and gravitational influence shape the stellar orbits and dust cloud chemistry nearby.", | |
| "health_pct": 40, "moons": "N/A", "direction": "Galactic Center", "surface": "Singularity", "air_index": "Accretion Disk", "human_like": "Zero", "perplexity": 0.99}, | |
| {"id": "BH_M87", "name": "M87's Black Hole (Supermassive)", "color": "0xAAAAAA", "detail": "The first black hole imaged. Its massive jets extend for thousands of light-years, impacting the entire M87 cluster's biology by stripping gas from forming galaxies.", | |
| "health_pct": 30, "moons": "N/A", "direction": "Active Jetting", "surface": "Event Horizon", "air_index": "Relativistic Plasma", "human_like": "Zero", "perplexity": 0.99}, | |
| {"id": "BH_V404CYGNI", "name": "V404 Cygni (Stellar Mass)", "color": "0x00FFFF", "detail": "A highly active stellar-mass black hole in a binary system, known for frequent X-ray flares. The intense burst radiation is highly mutagenic to any biological neighbors.", | |
| "health_pct": 55, "moons": "N/A", "direction": "Local Source", "surface": "Binary System", "air_index": "High X-ray Flux", "human_like": "Zero", "perplexity": 0.97}, | |
| {"id": "BH_GROJ1655", "name": "GRO J1655-40 (Stellar Mass)", "color": "0xCC00AA", "detail": "An exceptionally fast-spinning black hole. The frame-dragging effect (Lense-Thirring effect) around it creates unique environmental physics that could theoretically affect orbiting matter.", | |
| "health_pct": 45, "moons": "N/A", "direction": "Rapid Spin", "surface": "Accretion Disk", "air_index": "X-ray/Gamma", "human_like": "Zero", "perplexity": 0.98}, | |
| {"id": "BH_PRIMORDIAL", "name": "Theoretic Primordial BH", "color": "0x333333", "detail": "Hypothesized to have formed in the early universe. Could potentially be a component of dark matter, and their minimal interaction makes them irrelevant to biological systems.", | |
| "health_pct": 5, "moons": "N/A", "direction": "Randomized", "surface": "Theoretic", "air_index": "Vacuum", "human_like": "Zero", "perplexity": 1.00}, | |
| ] | |
| } | |
| } | |
| # --- 2. PAGE CONFIGURATION --- | |
| st.set_page_config(page_title="BioDS - Space Biology Data System", page_icon="🔭", layout="wide") | |
| # --- 3. CONSTANTS --- | |
| ACCENT_COLOR = "#00CCFF" | |
| # --- 4. SESSION STATE INITIALIZATION --- | |
| if 'page' not in st.session_state: | |
| st.session_state.page = "app" | |
| if 'current_section' not in st.session_state: | |
| st.session_state.current_section = list(SPACE_DATA.keys())[0] if SPACE_DATA else None | |
| if 'selected_item' not in st.session_state: | |
| st.session_state.selected_item = None | |
| if 'dashboard_section' not in st.session_state: | |
| st.session_state.dashboard_section = list(SPACE_DATA.keys())[0] if SPACE_DATA else None | |
| # --- 5. NAVIGATION --- | |
| def render_navbar(): | |
| """Renders the navigation bar.""" | |
| st.markdown(f""" | |
| <div style="position: fixed; top: 0; left: 0; right: 0; z-index: 1000; background-color: #0d0d0d; padding: 1rem 2rem; border-bottom: 1px solid rgba(255, 255, 255, 0.1);"> | |
| <div style="display: flex; justify-content: space-between; align-items: center;"> | |
| <div style="font-family: 'Inter', sans-serif; font-size: 24px; font-weight: bold; color: {ACCENT_COLOR};">BioDS.</div> | |
| <div style="display: flex; gap: 20px;"> | |
| </div> | |
| </div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| cols_nav = st.columns([1, 1]) | |
| if cols_nav[0].button("🧬 App View", key="nav_app_view"): | |
| st.session_state.page = "app" | |
| st.rerun() | |
| if cols_nav[1].button("🔭 Dashboard", key="nav_dashboard"): | |
| st.session_state.page = "dashboard" | |
| st.rerun() | |
| st.markdown("<hr style='margin: 0; border-top: 1px solid rgba(255, 255, 255, 0.1);'>", unsafe_allow_html=True) | |
| # --- 6. DASHBOARD FUNCTIONS --- | |
| def render_dashboard_navigation(): | |
| NAV_KEYS = ['MilkyWayGalaxy', 'AndromedaGalaxy', 'Interstellar', 'OtherGalaxies', 'BlackHoles'] | |
| cols = st.columns(len(NAV_KEYS)) | |
| title_map = { | |
| 'MilkyWayGalaxy': 'Milky Way', | |
| 'AndromedaGalaxy': 'Andromeda', | |
| 'Interstellar': 'Interstellar', | |
| 'OtherGalaxies': 'Galaxies', | |
| 'BlackHoles': 'Black Holes' | |
| } | |
| for i, key in enumerate(NAV_KEYS): | |
| title = title_map.get(key, key) | |
| is_active = (key == st.session_state.dashboard_section) | |
| if cols[i].button(title, key=f"dash_nav_{key}", use_container_width=True, type="primary" if is_active else "secondary"): | |
| st.session_state.dashboard_section = key | |
| st.rerun() | |
| def render_dashboard_content(section_key): | |
| data = SPACE_DATA[section_key] | |
| num_items = len(data['items']) | |
| st.markdown(f"### {data['title']}") | |
| st.markdown("---") | |
| col1, col2, col3 = st.columns(3) | |
| col1.metric("Total Bodies Tracked", str(num_items), delta=f"+{num_items*3}% Potential Habitability") | |
| col2.metric("Dominant Element", "Carbon", "98% Confidence") | |
| col3.metric("Latest Entry", data['items'][0]['name'], "Updated 2h ago") | |
| st.markdown("---") | |
| summary_analysis = { | |
| 'MilkyWayGalaxy': "Local systems show high concentration of water-based life candidates, especially around icy moons and newly discovered exoplanet systems (like TRAPPIST-1).", | |
| 'AndromedaGalaxy': "Intergalactic analysis points to high gravitational perturbations, suggesting life would need to be resilient to frequent, high-energy events.", | |
| 'Interstellar': "The interstellar medium is a reservoir of complex organic molecules. Research focuses on cryo-protection for panspermia viability.", | |
| 'OtherGalaxies': "Highly diverse ecosystems. Interacting galaxies indicate transient periods of sterilization followed by rapid chemical rejuvenation.", | |
| 'BlackHoles': "These regions are primarily studied for their energy output's impact on distant habitable zones.", | |
| } | |
| st.info(f"**Section Analysis:** {summary_analysis.get(section_key, 'No analysis available.')}") | |
| st.markdown("---") | |
| st.subheader("Biological Profile Overview") | |
| for item in data['items']: | |
| with st.expander(f"**{item['name']}**"): | |
| st.write(item['detail']) | |
| def dashboard_page(): | |
| st.markdown(f'<h1 style="color: {ACCENT_COLOR};">BioDS Dashboard</h1>', unsafe_allow_html=True) | |
| st.subheader("Welcome to the BioDS Dashboard!") | |
| st.markdown("---") | |
| render_dashboard_navigation() | |
| render_dashboard_content(st.session_state.dashboard_section) | |
| # --- 7. APP VIEW FUNCTIONS --- | |
| def render_item_details(item): | |
| st.markdown(f"<h2 style='color:#{item['color'].replace('0x', '')};'>{item['name']}</h2>", unsafe_allow_html=True) | |
| st.markdown(f"**Context:** {st.session_state.current_section}") | |
| st.markdown(f"{item['detail']}") | |
| st.markdown("---") | |
| st.subheader("Biological & Celestial Metrics") | |
| health_progress = item['health_pct'] / 100.0 | |
| st.progress(health_progress, text=f"System Health: **{item['health_pct']}%**") | |
| col_l, col_r = st.columns(2) | |
| with col_l: | |
| st.write(f"**Moons/Satellites:** {item['moons']}") | |
| st.write(f"**Direction:** {item['direction']}") | |
| with col_r: | |
| st.write(f"**Surface:** {item['surface']}") | |
| st.write(f"**Air Index:** {item['air_index']}") | |
| st.markdown("---") | |
| st.subheader("Resource Allocation") | |
| bio_integrity = item['health_pct'] * 0.4 | |
| grav_quality = item['health_pct'] * 0.3 + (1 - item['perplexity']) * 30 | |
| atm_confidence = item['perplexity'] * 50 | |
| unallocated = max(1, 100 - (bio_integrity + grav_quality + atm_confidence)) | |
| df_data = pd.DataFrame({ | |
| 'Category': ['Bio-Scan Integrity', 'Gravimetric Data', 'Atmospheric Modeling', 'Unallocated'], | |
| 'Value': [bio_integrity, grav_quality, atm_confidence, unallocated] | |
| }) | |
| fig = px.pie(df_data, values='Value', names='Category', color_discrete_sequence=['#00CCFF', '#FF5555', '#AAAAAA', '#444444']) | |
| fig.update_layout(height=300, paper_bgcolor="rgba(0,0,0,0)", font=dict(color="#CCCCCC")) | |
| st.plotly_chart(fig, use_container_width=True, key=f"chart_{st.session_state.current_section}_{item['id']}") | |
| st.markdown("---") | |
| st.write(f"**Human-Like Viability:** {item['human_like']}") | |
| def bio_ds_page(): | |
| if st.session_state.current_section is None and SPACE_DATA: | |
| st.session_state.current_section = list(SPACE_DATA.keys())[0] | |
| st.markdown(f'<h1 style="color: {ACCENT_COLOR};">BioDS Data Explorer</h1>', unsafe_allow_html=True) | |
| st.markdown("---") | |
| NAV_KEYS = list(SPACE_DATA.keys()) | |
| NAV_TITLES = [SPACE_DATA[key]['title'].split(':')[0] for key in NAV_KEYS] | |
| tabs = st.tabs(NAV_TITLES) | |
| for i, key in enumerate(NAV_KEYS): | |
| with tabs[i]: | |
| st.session_state.current_section = key | |
| col_content, col_panel = st.columns([2, 1]) | |
| with col_content: | |
| current_data = SPACE_DATA[key] | |
| st.markdown(f"**Section:** {current_data['title']}") | |
| st.markdown("---") | |
| items_per_row = 3 | |
| num_items = len(current_data['items']) | |
| num_rows = (num_items + items_per_row - 1) // items_per_row | |
| for row in range(num_rows): | |
| row_cols = st.columns(items_per_row) | |
| for j in range(items_per_row): | |
| item_index = row * items_per_row + j | |
| if item_index < num_items: | |
| item = current_data['items'][item_index] | |
| with row_cols[j]: | |
| if st.button(f"✶ {item['name']}", key=f"crystal_{key}_{item['id']}", use_container_width=True): | |
| st.session_state.current_section = key | |
| st.session_state.selected_item = item | |
| st.rerun() | |
| with col_panel: | |
| if st.session_state.selected_item and st.session_state.current_section == key: | |
| render_item_details(st.session_state.selected_item) | |
| else: | |
| st.markdown("### Select a Celestial Body") | |
| st.info("Click on any star crystal to view its complete Space Biology profile.") | |
| # --- 8. MAIN APP --- | |
| def main_app(): | |
| st.markdown(f""" | |
| <style> | |
| .stApp {{ | |
| background-color: #0d0d0d; | |
| color: #ffffff; | |
| }} | |
| .stButton > button {{ | |
| background-color: #1a1a1a; | |
| color: #ffffff; | |
| border: 1px solid rgba(255, 255, 255, 0.1); | |
| }} | |
| .stButton > button:hover {{ | |
| background-color: {ACCENT_COLOR}; | |
| color: #0d0d0d; | |
| }} | |
| </style> | |
| """, unsafe_allow_html=True) | |
| render_navbar() | |
| if st.session_state.page == "app": | |
| bio_ds_page() | |
| elif st.session_state.page == "dashboard": | |
| dashboard_page() | |
| if __name__ == "__main__": | |
| main_app() |