mohAhmad commited on
Commit
74fa26b
1 Parent(s): 0a48ded

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -2,7 +2,6 @@ import streamlit as st
2
  import pyttsx3
3
  from transformers import pipeline
4
  from PIL import Image, ImageDraw
5
- import random
6
 
7
  # Set up the app
8
  st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
@@ -16,7 +15,13 @@ def load_storytelling_model():
16
  story_generator = load_storytelling_model()
17
 
18
  # Initialize TTS engine
19
- engine = pyttsx3.init()
 
 
 
 
 
 
20
 
21
  # App title and description
22
  st.title("ChiliDron")
@@ -72,9 +77,11 @@ elif options == "Guided Meditation":
72
 
73
  if st.button("Play Meditation"):
74
  st.spinner("Playing meditation audio...")
75
- engine.save_to_file(meditation_text, 'meditation.mp3')
76
- engine.runAndWait()
77
- st.audio('meditation.mp3', format='audio/mp3')
 
 
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)
 
2
  import pyttsx3
3
  from transformers import pipeline
4
  from PIL import Image, ImageDraw
 
5
 
6
  # Set up the app
7
  st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="🎨")
 
15
  story_generator = load_storytelling_model()
16
 
17
  # Initialize TTS engine
18
+ def initialize_tts():
19
+ try:
20
+ engine = pyttsx3.init()
21
+ return engine
22
+ except Exception as e:
23
+ st.error(f"Error initializing text-to-speech engine: {e}")
24
+ return None
25
 
26
  # App title and description
27
  st.title("ChiliDron")
 
77
 
78
  if st.button("Play Meditation"):
79
  st.spinner("Playing meditation audio...")
80
+ tts_engine = initialize_tts()
81
+ if tts_engine:
82
+ tts_engine.save_to_file(meditation_text, 'meditation.mp3')
83
+ tts_engine.runAndWait()
84
+ st.audio('meditation.mp3', format='audio/mp3')
85
 
86
  # Footer
87
  st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with ❤️ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)