Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,22 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
tts_title = "Text to Speech Translation"
|
6 |
-
tts_examples = ["I love learning machine learning", "How do you do?"]
|
7 |
-
tts_demo = gr.Interface.load(
|
8 |
-
"huggingface/facebook/fastspeech2-en-ljspeech",
|
9 |
-
title=tts_title,
|
10 |
-
examples=tts_examples,
|
11 |
-
description="Give me something to say!",
|
12 |
-
)
|
13 |
-
|
14 |
-
# Load emotion classification model
|
15 |
-
emotion_model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
|
16 |
-
emotion_model = pipeline("text-classification", model=emotion_model_checkpoint)
|
17 |
-
|
18 |
-
def classify_emotion_and_speech(text=""):
|
19 |
-
# Emotion classification
|
20 |
-
emotion_label = emotion_model(text)[0]["label"]
|
21 |
-
|
22 |
-
# Adjust speech synthesis parameters based on emotion_label.
|
23 |
-
# Customize this part based on the emotion_label.
|
24 |
|
25 |
-
|
26 |
-
speech_output = f"Emotion: {emotion_label}, Text: {text}"
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
emotion_description = "This AI model classifies texts expressing human emotion and converts them into speech."
|
32 |
-
emotion_examples = [["He is very happy today", "Free Palestine"]]
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
"background-color": "#007bff",
|
38 |
-
"color": "#fff",
|
39 |
-
"padding": "20px",
|
40 |
-
},
|
41 |
-
"textbox": {
|
42 |
-
"background-color": "#fff",
|
43 |
-
"border-radius": "5px",
|
44 |
-
"padding": "10px",
|
45 |
-
"margin-bottom": "10px",
|
46 |
-
},
|
47 |
-
"button": {
|
48 |
-
"background-color": "#007bff",
|
49 |
-
"color": "#fff",
|
50 |
-
"padding": "10px",
|
51 |
-
"border-radius": "5px",
|
52 |
-
"cursor": "pointer",
|
53 |
-
},
|
54 |
-
"label": {
|
55 |
-
"color": "#fff",
|
56 |
-
},
|
57 |
-
}
|
58 |
|
59 |
-
|
60 |
-
fn=classify_emotion_and_speech,
|
61 |
-
inputs="textbox",
|
62 |
-
outputs=["text", "audio"],
|
63 |
-
title=emotion_title,
|
64 |
-
theme=theme,
|
65 |
-
description=emotion_description,
|
66 |
-
examples=emotion_examples,
|
67 |
-
)
|
68 |
|
69 |
-
|
70 |
-
combined_demo_tabbed = gr.TabbedInterface([tts_demo, combined_demo], ["Text to Speech", "Texts Expressing Emotion with Speech"])
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
-
|
74 |
-
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
|
3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
tts = pipeline("text-to-speech", "facebook/wav2vec2-base-960h")
|
|
|
6 |
|
7 |
+
def text_to_speech(text):
|
8 |
+
audio = tts(text)[0]["audio"]
|
9 |
+
return audio
|
10 |
|
11 |
+
demo = gr.Blocks()
|
|
|
|
|
12 |
|
13 |
+
with demo:
|
14 |
+
text_input = gr.Textbox()
|
15 |
+
audio_output = gr.Audio()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
b1 = gr.Button("Convert to Speech")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
b1.click(text_to_speech, inputs=text_input, outputs=audio_output)
|
|
|
20 |
|
21 |
if __name__ == "__main__":
|
22 |
+
demo.launch()
|
|