|
import streamlit as st |
|
import pyttsx3 |
|
from transformers import pipeline |
|
from PIL import Image, ImageDraw |
|
|
|
|
|
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨") |
|
|
|
|
|
@st.cache_resource |
|
def load_storytelling_model(): |
|
return pipeline("text-generation", model="gpt2") |
|
|
|
|
|
story_generator = load_storytelling_model() |
|
|
|
|
|
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 |
|
|
|
|
|
st.title("ChiliDron") |
|
st.subheader("A fun, interactive, and educational app for kids!") |
|
|
|
|
|
st.sidebar.title("Navigate") |
|
options = st.sidebar.radio("Go to", ["Interactive Storyteller", "Digital Art Studio", "Guided Meditation"]) |
|
|
|
|
|
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']) |
|
|
|
|
|
if options == "Digital Art Studio": |
|
st.header("π¨ Digital Art Studio") |
|
st.write("Draw and create your own masterpiece!") |
|
|
|
|
|
width, height = 400, 400 |
|
canvas = Image.new('RGB', (width, height), (255, 255, 255)) |
|
draw = ImageDraw.Draw(canvas) |
|
|
|
|
|
st.write("Use the input boxes below to draw on the canvas (x, y coordinates and color)") |
|
|
|
|
|
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) |
|
|
|
|
|
st.image(canvas, caption='Your Drawing', use_column_width=True) |
|
|
|
|
|
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') |
|
|
|
|
|
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with β€οΈ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True) |
|
|