sunbal7 commited on
Commit
db4be6b
·
verified ·
1 Parent(s): 93ccd38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -2,7 +2,6 @@
2
  import streamlit as st
3
  import time
4
  import random
5
- import json
6
  import textwrap
7
  import os
8
  import base64
@@ -10,10 +9,9 @@ from io import BytesIO
10
  from PIL import Image, ImageDraw, ImageFont
11
  import numpy as np
12
  from gtts import gTTS
13
- from pygame import mixer
14
  import tempfile
15
- import requests
16
- from transformers import pipeline, set_seed
17
 
18
  # Set up the page
19
  st.set_page_config(
@@ -23,9 +21,6 @@ st.set_page_config(
23
  initial_sidebar_state="expanded"
24
  )
25
 
26
- # Initialize pygame mixer
27
- mixer.init()
28
-
29
  # Custom CSS
30
  st.markdown("""
31
  <style>
@@ -174,6 +169,12 @@ st.markdown("""
174
  .stProgress > div > div > div {
175
  background-color: #ff5722 !important;
176
  }
 
 
 
 
 
 
177
  </style>
178
  """, unsafe_allow_html=True)
179
 
@@ -599,12 +600,16 @@ with col2:
599
 
600
  # Play voice explanation
601
  if st.session_state.voice_enabled and 'speech_file' in st.session_state:
602
- if st.button("🔊 Play Tavus Explanation", use_container_width=True):
603
- try:
604
- mixer.music.load(st.session_state.speech_file)
605
- mixer.music.play()
606
- except:
607
- st.warning("Couldn't play audio. Try enabling sound in your browser.")
 
 
 
 
608
 
609
  elif st.session_state.animation_generated:
610
  st.warning("Couldn't generate animation. Try a different story!")
@@ -789,4 +794,4 @@ st.markdown("""
789
  Transforming stories into games since 2023 | No API Keys Required!
790
  </p>
791
  </center>
792
- """, unsafe_allow_html=True)
 
2
  import streamlit as st
3
  import time
4
  import random
 
5
  import textwrap
6
  import os
7
  import base64
 
9
  from PIL import Image, ImageDraw, ImageFont
10
  import numpy as np
11
  from gtts import gTTS
 
12
  import tempfile
13
+ import subprocess
14
+ from transformers import pipeline
15
 
16
  # Set up the page
17
  st.set_page_config(
 
21
  initial_sidebar_state="expanded"
22
  )
23
 
 
 
 
24
  # Custom CSS
25
  st.markdown("""
26
  <style>
 
169
  .stProgress > div > div > div {
170
  background-color: #ff5722 !important;
171
  }
172
+
173
+ /* Audio player styling */
174
+ .audio-player {
175
+ width: 100%;
176
+ margin-top: 10px;
177
+ }
178
  </style>
179
  """, unsafe_allow_html=True)
180
 
 
600
 
601
  # Play voice explanation
602
  if st.session_state.voice_enabled and 'speech_file' in st.session_state:
603
+ try:
604
+ # Read audio file and convert to base64
605
+ with open(st.session_state.speech_file, "rb") as f:
606
+ audio_bytes = f.read()
607
+
608
+ # Display audio player
609
+ st.audio(audio_bytes, format='audio/mp3')
610
+
611
+ except Exception as e:
612
+ st.warning(f"Couldn't load audio: {e}")
613
 
614
  elif st.session_state.animation_generated:
615
  st.warning("Couldn't generate animation. Try a different story!")
 
794
  Transforming stories into games since 2023 | No API Keys Required!
795
  </p>
796
  </center>
797
+ """, unsafe_allow_html=True)