mohAhmad commited on
Commit
8da67e2
1 Parent(s): 928626e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -54
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import streamlit as st
2
- from PIL import Image, ImageDraw, ImageColor
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", "Digital Art Studio", "Guided Meditation"])
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=200, num_return_sequences=1)
49
  st.success(story[0]['generated_text'])
50
 
51
- # Digital Art Studio
52
- elif options == "Digital Art Studio":
53
- # Define the image URL
54
- image_url = "https://huggingface.co/spaces/mohAhmad/ChildDron/raw/main/26141935e868bc1fd22c44de3dc463df.jpg"
55
-
56
- # Load the image from the URL
57
- response = requests.get(image_url)
58
- img = Image.open(BytesIO(response.content)).convert("RGBA")
59
-
60
- # Display the original image
61
- st.header("🎨 Cartoon Coloring Studio")
62
- st.write("Color the cartoon image!")
63
-
64
- # Color picker
65
- color = st.color_picker("Pick a color", "#000000")
66
-
67
- # Create a drawing canvas on top of the image
68
- canvas_width, canvas_height = img.size
69
- drawing_img = img.copy()
70
- draw = ImageDraw.Draw(drawing_img)
71
-
72
- # Display the image
73
- st.image(img, caption='Cartoon Image', use_column_width=True)
74
-
75
- # Function to color the image
76
- def color_image(x, y, color):
77
- if 0 <= x < canvas_width and 0 <= y < canvas_height:
78
- draw.point((x, y), fill=ImageColor.getrgb(color))
79
-
80
- # Input for coloring
81
- click_x = st.slider("Click X", 0, canvas_width - 1, step=1)
82
- click_y = st.slider("Click Y", 0, canvas_height - 1, step=1)
83
-
84
- if st.button("Color"):
85
- color_image(click_x, click_y, color)
86
- st.image(drawing_img, caption='Your Colored Cartoon', use_column_width=True)
87
-
88
- # Optionally, save the colored image
89
- if st.button("Save Drawing"):
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
- tts_engine = initialize_tts()
103
- if tts_engine:
104
- tts_engine.save_to_file(meditation_text, 'meditation.mp3')
105
- tts_engine.runAndWait()
106
- st.audio('meditation.mp3', format='audio/mp3')
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)