Spaces:
Build error
Build error
| # app.py | |
| import streamlit as st | |
| import pydeck as pdk | |
| import pandas as pd | |
| import json | |
| import os | |
| from pathlib import Path | |
| class HistoricalViewer: | |
| def __init__(self): | |
| self.load_config() | |
| self.setup_directories() | |
| def load_config(self): | |
| """Load application configuration""" | |
| self.config = { | |
| "models_dir": "models", | |
| "stories_dir": "stories", | |
| "supported_languages": ["en", "es"] | |
| } | |
| def setup_directories(self): | |
| """Create necessary directories""" | |
| for dir_name in [self.config["models_dir"], self.config["stories_dir"]]: | |
| Path(dir_name).mkdir(exist_ok=True) | |
| def load_story(self, story_id): | |
| """Load story content from JSON file""" | |
| story_path = Path(self.config["stories_dir"]) / f"{story_id}.json" | |
| if story_path.exists(): | |
| with open(story_path, 'r', encoding='utf-8') as f: | |
| return json.load(f) | |
| return None | |
| def create_3d_map(self, latitude=41.8925, longitude=12.4853): | |
| """Create 3D map visualization using PyDeck""" | |
| view_state = pdk.ViewState( | |
| latitude=latitude, | |
| longitude=longitude, | |
| zoom=18, | |
| pitch=45, | |
| bearing=0 | |
| ) | |
| # Create a simple 3D layer | |
| layer = pdk.Layer( | |
| 'ScatterplotLayer', | |
| data=pd.DataFrame({ | |
| 'latitude': [latitude], | |
| 'longitude': [longitude] | |
| }), | |
| get_position=['longitude', 'latitude'], | |
| get_color=[200, 30, 0, 160], | |
| get_radius=5, | |
| pickable=True | |
| ) | |
| # Create the deck | |
| deck = pdk.Deck( | |
| map_style='mapbox://styles/mapbox/satellite-v9', | |
| initial_view_state=view_state, | |
| layers=[layer] | |
| ) | |
| return deck | |
| def main(): | |
| st.set_page_config(page_title="Historical Site Viewer", layout="wide") | |
| viewer = HistoricalViewer() | |
| # Sidebar for controls | |
| with st.sidebar: | |
| st.title("Navigation") | |
| language = st.selectbox("Select Language", viewer.config["supported_languages"]) | |
| # Load story selection | |
| story_files = list(Path(viewer.config["stories_dir"]).glob("*.json")) | |
| story_names = [f.stem for f in story_files] | |
| if story_names: | |
| selected_story = st.selectbox("Select Story", story_names) | |
| story_data = viewer.load_story(selected_story) | |
| else: | |
| st.warning("No stories available. Please add story JSON files to the stories directory.") | |
| story_data = None | |
| # Main content area | |
| col1, col2 = st.columns([2, 1]) | |
| with col1: | |
| st.title("Historical Site View") | |
| # Display 3D map | |
| deck = viewer.create_3d_map() | |
| st.pydeck_chart(deck) | |
| with col2: | |
| st.title("Story Navigation") | |
| if story_data: | |
| current_node = story_data["nodes"]["start"] | |
| st.markdown(current_node["content"][language]) | |
| st.subheader("Choices") | |
| for choice in current_node["choices"]: | |
| if st.button(choice["text"][language]): | |
| st.session_state.current_node = choice["next_node"] | |
| st.experimental_rerun() | |
| if __name__ == "__main__": | |
| main() |