Spaces:
Running
Running
Lucasstranger1
commited on
Commit
•
59ec3b4
1
Parent(s):
e1d89e6
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import requests
|
4 |
-
import
|
5 |
from transformers import pipeline
|
6 |
from PIL import Image
|
7 |
from dotenv import load_dotenv
|
@@ -32,11 +32,11 @@ def generate_text_based_on_mood(emotion):
|
|
32 |
response = generator(prompt, max_length=50, num_return_sequences=1)
|
33 |
return response[0]['generated_text']
|
34 |
|
35 |
-
# Function to convert text to speech
|
36 |
def text_to_speech(text):
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
# Streamlit UI
|
42 |
st.title("Facial Expression Mood Detector")
|
@@ -66,4 +66,7 @@ if uploaded_file is not None:
|
|
66 |
st.write(joke)
|
67 |
|
68 |
# Convert the generated joke to audio
|
69 |
-
text_to_speech(joke)
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import requests
|
4 |
+
from gtts import gTTS
|
5 |
from transformers import pipeline
|
6 |
from PIL import Image
|
7 |
from dotenv import load_dotenv
|
|
|
32 |
response = generator(prompt, max_length=50, num_return_sequences=1)
|
33 |
return response[0]['generated_text']
|
34 |
|
35 |
+
# Function to convert text to speech using gTTS
|
36 |
def text_to_speech(text):
|
37 |
+
tts = gTTS(text, lang='en')
|
38 |
+
tts.save("output.mp3") # Save to a file
|
39 |
+
return "output.mp3" # Return the filename for playing
|
40 |
|
41 |
# Streamlit UI
|
42 |
st.title("Facial Expression Mood Detector")
|
|
|
66 |
st.write(joke)
|
67 |
|
68 |
# Convert the generated joke to audio
|
69 |
+
audio_file = text_to_speech(joke)
|
70 |
+
|
71 |
+
# Provide an audio player in the Streamlit app
|
72 |
+
st.audio(audio_file) # Streamlit will handle playback
|