mohAhmad commited on
Commit
cc8640e
β€’
1 Parent(s): 769a0a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image, ImageDraw, ImageFont
4
+ import random
5
+
6
+ # Set up the app
7
+ st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
8
+
9
+ # Load Hugging Face models using cache
10
+ @st.cache_resource
11
+ def load_storytelling_model():
12
+ return pipeline("text-generation", model="gpt2")
13
+
14
+ @st.cache_resource
15
+ def load_text_to_speech_model():
16
+ return pipeline("text-to-speech", model="espnet/kan-bayashi_ljspeech_vits")
17
+
18
+ # Load models
19
+ story_generator = load_storytelling_model()
20
+ tts = load_text_to_speech_model()
21
+
22
+ # App title and description
23
+ st.title("ChiliDron")
24
+ st.subheader("A fun, interactive, and educational app for kids!")
25
+
26
+ # Sidebar navigation
27
+ st.sidebar.title("Navigate")
28
+ options = st.sidebar.radio("Go to", ["Interactive Storyteller", "Digital Art Studio", "Guided Meditation"])
29
+
30
+ # Interactive Storyteller
31
+ if options == "Interactive Storyteller":
32
+ st.header("πŸ“ Interactive Storyteller")
33
+ st.write("Create your own story by selecting characters and plot points!")
34
+
35
+ character = st.selectbox("Choose a character:", ["A Brave Knight", "A Clever Princess", "A Funny Alien", "A Curious Scientist"])
36
+ setting = st.selectbox("Choose a setting:", ["In a magical forest", "On a distant planet", "In an ancient castle", "At a science lab"])
37
+ plot = st.selectbox("Choose a plot point:", ["Finds a mysterious map", "Discovers a secret passage", "Meets a talking animal", "Invents a cool gadget"])
38
+
39
+ if st.button("Create Story"):
40
+ with st.spinner("Generating your story..."):
41
+ prompt = f"Once upon a time, {character} was {setting} when they {plot}. And then,"
42
+ story = story_generator(prompt, max_length=200, num_return_sequences=1)
43
+ st.success(story[0]['generated_text'])
44
+
45
+ # Digital Art Studio
46
+ elif options == "Digital Art Studio":
47
+ st.header("🎨 Digital Art Studio")
48
+ st.write("Draw and create your own masterpiece!")
49
+
50
+ # Simple canvas with PIL
51
+ width, height = 400, 400
52
+ canvas = Image.new('RGB', (width, height), (255, 255, 255))
53
+ draw = ImageDraw.Draw(canvas)
54
+
55
+ # Draw instructions
56
+ st.write("Use the input boxes below to draw on the canvas (x, y coordinates and color)")
57
+
58
+ # Input fields for drawing
59
+ x = st.number_input("X Coordinate", min_value=0, max_value=width-1, step=1)
60
+ y = st.number_input("Y Coordinate", min_value=0, max_value=height-1, step=1)
61
+ color = st.color_picker("Pick a color", "#000000")
62
+
63
+ if st.button("Draw"):
64
+ draw.point((x, y), fill=color)
65
+ st.image(canvas)
66
+
67
+ # Guided Meditation for Kids
68
+ elif options == "Guided Meditation":
69
+ st.header("πŸ§˜β€β™‚οΈ Guided Meditation for Kids")
70
+ st.write("Relax and listen to a calming meditation.")
71
+
72
+ 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."
73
+
74
+ if st.button("Play Meditation"):
75
+ with st.spinner("Generating meditation audio..."):
76
+ speech = tts(meditation_text)
77
+ st.audio(speech['wav'], format="audio/wav")
78
+
79
+ # Footer
80
+ st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with ❀️ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)