import streamlit as st from transformers import pipeline from PIL import Image, ImageDraw, ImageFont import random # 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") @st.cache_resource def load_text_to_speech_model(): return pipeline("text-to-speech", model="espnet/kan-bayashi_ljspeech_vits") # Load models story_generator = load_storytelling_model() tts = load_text_to_speech_model() # 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 elif 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) # 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"): with st.spinner("Generating meditation audio..."): speech = tts(meditation_text) st.audio(speech['wav'], format="audio/wav") # Footer st.markdown("", unsafe_allow_html=True)