# app.py import streamlit as st from streamlit.components.v1 import html from story_engine.story_builder import build_story st.markdown(""" """, unsafe_allow_html=True) st.set_page_config(page_title="WikiTales", layout="centered") st.title("📖 WikiTales – Interactive Historical Storybooks") with st.container(): st.markdown("#### 🔍 Enter a historical figure or event:") topic = st.text_input( label="Search Topic", placeholder="e.g., French Revolution", key="search_box", label_visibility="collapsed" ) narrator = st.selectbox( "Choose Narrator Voice", options=["📚 Neutral Historian", "📰 Wartime Journalist", "👩🌾 Eyewitness", "🧙 Fictional Guide", "🤖 AI Assistant"], index=0 ) # ------------------------- # Carousel Renderer Function # ------------------------- def render_image_carousel(images): if not images: st.warning("No images found.") return # Build slides slides = "" for idx, img in enumerate(images): slides += f"""
""" html_code = f""" """ html(html_code, height=420) # ------------------------- # Main Search + Display # ------------------------- if topic: with st.spinner(f"Generating story for '{topic}'..."): story_data = build_story(topic, narrator) story = story_data["story"] images = story_data["images"] wikibooks = story_data.get("wikibooks", []) # ✅ added if story: render_image_carousel(images) st.markdown(f"#### 🎙️ Narrated by: {narrator}") st.markdown("## 🧠 Generated Story") with st.container(): st.markdown(story, unsafe_allow_html=True) # ✅ SIDEBAR: Wikibooks Deep Dive if wikibooks: with st.sidebar: st.markdown("## 📚 Learn More on Wikibooks") for module in wikibooks: st.markdown(f"- [{module['title']}]({module['link']})") else: st.error("Sorry, we couldn't build a story. Try another topic.")