import streamlit as st import pyttsx3 from transformers import pipeline from PIL import Image, ImageDraw # Set up the app st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨") # Load Hugging Face models using cache @st.cache_resource def load_storytelling_model(): return pipeline("text-generation", model="gpt2") # Load models story_generator = load_storytelling_model() # Initialize TTS engine def initialize_tts(): try: engine = pyttsx3.init() return engine except Exception as e: st.error(f"Error initializing text-to-speech engine: {e}") return None # App title and description st.title("ChiliDron") st.subheader("A fun, interactive, and educational app for kids!") # Sidebar navigation st.sidebar.title("Navigate") options = st.sidebar.radio("Go to", ["Interactive Storyteller", "Digital Art Studio", "Guided Meditation"]) # Interactive Storyteller if options == "Interactive Storyteller": st.header("📝 Interactive Storyteller") st.write("Create your own story by selecting characters and plot points!") character = st.selectbox("Choose a character:", ["A Brave Knight", "A Clever Princess", "A Funny Alien", "A Curious Scientist"]) setting = st.selectbox("Choose a setting:", ["In a magical forest", "On a distant planet", "In an ancient castle", "At a science lab"]) plot = st.selectbox("Choose a plot point:", ["Finds a mysterious map", "Discovers a secret passage", "Meets a talking animal", "Invents a cool gadget"]) if st.button("Create Story"): with st.spinner("Generating your story..."): prompt = f"Once upon a time, {character} was {setting} when they {plot}. And then," story = story_generator(prompt, max_length=200, num_return_sequences=1) st.success(story[0]['generated_text']) # Digital Art Studio # Digital Art Studio if options == "Digital Art Studio": st.header("🎨 Digital Art Studio") st.write("Draw and create your own masterpiece!") # Simple canvas with PIL width, height = 400, 400 canvas = Image.new('RGB', (width, height), (255, 255, 255)) draw = ImageDraw.Draw(canvas) # Draw instructions st.write("Use the input boxes below to draw on the canvas (x, y coordinates and color)") # Input fields for drawing x = st.number_input("X Coordinate", min_value=0, max_value=width-1, step=1) y = st.number_input("Y Coordinate", min_value=0, max_value=height-1, step=1) color = st.color_picker("Pick a color", "#000000") if st.button("Draw"): draw.point((x, y), fill=color) st.image(canvas, caption='Your Drawing', use_column_width=True) # Display the drawing st.image(canvas, caption='Your Drawing', use_column_width=True) # Guided Meditation for Kids elif options == "Guided Meditation": st.header("🧘‍♂️ Guided Meditation for Kids") st.write("Relax and listen to a calming meditation.") meditation_text = "Close your eyes and take a deep breath. Imagine you are in a peaceful forest, with birds singing and leaves rustling in the wind." if st.button("Play Meditation"): st.spinner("Playing meditation audio...") tts_engine = initialize_tts() if tts_engine: tts_engine.save_to_file(meditation_text, 'meditation.mp3') tts_engine.runAndWait() st.audio('meditation.mp3', format='audio/mp3') # Footer st.markdown("", unsafe_allow_html=True)