|
import streamlit as st |
|
from transformers import pipeline |
|
from PIL import Image, ImageDraw, ImageFont |
|
import random |
|
|
|
|
|
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨") |
|
|
|
|
|
@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") |
|
|
|
|
|
story_generator = load_storytelling_model() |
|
tts = load_text_to_speech_model() |
|
|
|
|
|
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']) |
|
|
|
|
|
elif 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) |
|
|
|
|
|
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") |
|
|
|
|
|
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with β€οΈ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True) |
|
|