Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
import requests
|
4 |
-
from io import BytesIO
|
5 |
-
from transformers import pipeline
|
6 |
import pyttsx3
|
|
|
7 |
|
8 |
# Set up the app
|
9 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
|
@@ -11,10 +9,17 @@ st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
|
|
11 |
# Load Hugging Face models using cache
|
12 |
@st.cache_resource
|
13 |
def load_storytelling_model():
|
14 |
-
return pipeline("text-generation", model="gpt2")
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Load models
|
17 |
story_generator = load_storytelling_model()
|
|
|
18 |
|
19 |
# Initialize TTS engine
|
20 |
def initialize_tts():
|
@@ -31,7 +36,7 @@ st.subheader("A fun, interactive, and educational app for kids!")
|
|
31 |
|
32 |
# Sidebar navigation
|
33 |
st.sidebar.title("Navigate")
|
34 |
-
options = st.sidebar.radio("Go to", ["Interactive Storyteller", "
|
35 |
|
36 |
# Interactive Storyteller
|
37 |
if options == "Interactive Storyteller":
|
@@ -45,50 +50,48 @@ if options == "Interactive Storyteller":
|
|
45 |
if st.button("Create Story"):
|
46 |
with st.spinner("Generating your story..."):
|
47 |
prompt = f"Once upon a time, {character} was {setting} when they {plot}. And then,"
|
48 |
-
story = story_generator(prompt, max_length=
|
49 |
st.success(story[0]['generated_text'])
|
50 |
|
51 |
-
#
|
52 |
-
elif options == "
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
drawing_img.save("colored_cartoon.png")
|
91 |
-
st.success("Drawing saved as colored_cartoon.png!")
|
92 |
|
93 |
# Guided Meditation for Kids
|
94 |
elif options == "Guided Meditation":
|
@@ -98,12 +101,12 @@ elif options == "Guided Meditation":
|
|
98 |
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."
|
99 |
|
100 |
if st.button("Play Meditation"):
|
101 |
-
st.spinner("Playing meditation audio...")
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
# Footer
|
109 |
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with ❤️ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
|
|
|
|
3 |
import pyttsx3
|
4 |
+
import random
|
5 |
|
6 |
# Set up the app
|
7 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
|
|
|
9 |
# Load Hugging Face models using cache
|
10 |
@st.cache_resource
|
11 |
def load_storytelling_model():
|
12 |
+
return pipeline("text-generation", model="bookbot/gpt2-indo-medium-kids-stories")
|
13 |
+
|
14 |
+
@st.cache_resource
|
15 |
+
def load_phoneme_model():
|
16 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("mirfan899/kids_phoneme_sm_model")
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained("mirfan899/kids_phoneme_sm_model")
|
18 |
+
return model, tokenizer
|
19 |
|
20 |
# Load models
|
21 |
story_generator = load_storytelling_model()
|
22 |
+
phoneme_model, phoneme_tokenizer = load_phoneme_model()
|
23 |
|
24 |
# Initialize TTS engine
|
25 |
def initialize_tts():
|
|
|
36 |
|
37 |
# Sidebar navigation
|
38 |
st.sidebar.title("Navigate")
|
39 |
+
options = st.sidebar.radio("Go to", ["Interactive Storyteller", "Joke and Fun Facts Generator", "Phoneme Practice", "Guided Meditation"])
|
40 |
|
41 |
# Interactive Storyteller
|
42 |
if options == "Interactive Storyteller":
|
|
|
50 |
if st.button("Create Story"):
|
51 |
with st.spinner("Generating your story..."):
|
52 |
prompt = f"Once upon a time, {character} was {setting} when they {plot}. And then,"
|
53 |
+
story = story_generator(prompt, max_length=500, num_return_sequences=1)
|
54 |
st.success(story[0]['generated_text'])
|
55 |
|
56 |
+
# Joke and Fun Facts Generator
|
57 |
+
elif options == "Joke and Fun Facts Generator":
|
58 |
+
st.header("🤣 Joke and Fun Facts Generator")
|
59 |
+
st.write("Get ready to laugh and learn with random jokes and fun facts!")
|
60 |
+
|
61 |
+
jokes = [
|
62 |
+
"Why did the scarecrow win an award? Because he was outstanding in his field!",
|
63 |
+
"Why don’t scientists trust atoms? Because they make up everything!",
|
64 |
+
"What do you get if you cross a vampire with a snowman? Frostbite!"
|
65 |
+
]
|
66 |
+
|
67 |
+
fun_facts = [
|
68 |
+
"Did you know that honey never spoils? Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible.",
|
69 |
+
"A day on Venus is longer than a year on Venus! It takes about 243 Earth days for Venus to rotate once, but only 225 Earth days to orbit the Sun.",
|
70 |
+
"Octopuses have three hearts and blue blood!"
|
71 |
+
]
|
72 |
+
|
73 |
+
if st.button("Tell me a joke!"):
|
74 |
+
st.write(random.choice(jokes))
|
75 |
+
|
76 |
+
if st.button("Tell me a fun fact!"):
|
77 |
+
st.write(random.choice(fun_facts))
|
78 |
+
|
79 |
+
# Phoneme Practice
|
80 |
+
elif options == "Phoneme Practice":
|
81 |
+
st.header("🔤 Phoneme Practice")
|
82 |
+
st.write("Learn how to pronounce words correctly!")
|
83 |
+
|
84 |
+
word_to_practice = st.text_input("Enter a word to practice its phonemes:")
|
85 |
+
|
86 |
+
if st.button("Get Phonemes"):
|
87 |
+
if word_to_practice:
|
88 |
+
with st.spinner("Analyzing phonemes..."):
|
89 |
+
inputs = phoneme_tokenizer.encode(word_to_practice, return_tensors="pt")
|
90 |
+
outputs = phoneme_model.generate(inputs)
|
91 |
+
phonemes = phoneme_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
92 |
+
st.write(f"Phonemes for '{word_to_practice}': {phonemes}")
|
93 |
+
else:
|
94 |
+
st.warning("Please enter a word to practice.")
|
|
|
|
|
95 |
|
96 |
# Guided Meditation for Kids
|
97 |
elif options == "Guided Meditation":
|
|
|
101 |
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."
|
102 |
|
103 |
if st.button("Play Meditation"):
|
104 |
+
with st.spinner("Playing meditation audio..."):
|
105 |
+
tts_engine = initialize_tts()
|
106 |
+
if tts_engine:
|
107 |
+
tts_engine.save_to_file(meditation_text, 'meditation.mp3')
|
108 |
+
tts_engine.runAndWait()
|
109 |
+
st.audio('meditation.mp3', format='audio/mp3')
|
110 |
|
111 |
# Footer
|
112 |
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with ❤️ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)
|