Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
description
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
},
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
},
|
37 |
-
}
|
38 |
-
|
39 |
-
gr.Interface(
|
40 |
-
fn=classify_emotion,
|
41 |
inputs="textbox",
|
42 |
-
outputs="text",
|
43 |
-
title=
|
44 |
theme=theme,
|
45 |
-
description=
|
46 |
-
examples=
|
47 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load text-to-speech model
|
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 |
+
# Replace the following line with your desired text-to-speech model and parameters.
|
26 |
+
speech_output = f"Emotion: {emotion_label}, Text: {text}"
|
27 |
+
|
28 |
+
return {"emotion_label": emotion_label, "audio": speech_output}
|
29 |
+
|
30 |
+
emotion_title = "Texts Expressing Emotion with Speech"
|
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 |
+
combined_demo = gr.Interface(
|
35 |
+
fn=classify_emotion_and_speech,
|
|
|
|
|
|
|
|
|
|
|
36 |
inputs="textbox",
|
37 |
+
outputs=["text", "audio"],
|
38 |
+
title=emotion_title,
|
39 |
theme=theme,
|
40 |
+
description=emotion_description,
|
41 |
+
examples=emotion_examples,
|
42 |
+
)
|
43 |
+
|
44 |
+
# Combine both demos into a Tabbed Interface
|
45 |
+
combined_demo_tabbed = gr.TabbedInterface([tts_demo, combined_demo], ["Text to Speech", "Texts Expressing Emotion with Speech"])
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
combined_demo_tabbed.launch()
|