Vishaltiwari2019 commited on
Commit
23610b0
·
verified ·
1 Parent(s): 9a8653b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -42
app.py CHANGED
@@ -1,47 +1,48 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
5
- emotion_model = pipeline("text-classification", model=model_checkpoint)
6
-
7
- def classify_emotion(text):
8
- label = emotion_model(text)[0]["label"]
9
- return label
10
-
11
- description = "This AI model is trained to classify texts expressing human emotion into different categories."
12
- title = "Texts Expressing Emotion"
13
- examples = [["He is very happy today", "Free Palestine"]]
14
-
15
- theme = {
16
- "container": {
17
- "background-color": "#007bff",
18
- "color": "#fff",
19
- "padding": "20px",
20
- },
21
- "textbox": {
22
- "background-color": "#fff",
23
- "border-radius": "5px",
24
- "padding": "10px",
25
- "margin-bottom": "10px",
26
- },
27
- "button": {
28
- "background-color": "#007bff",
29
- "color": "#fff",
30
- "padding": "10px",
31
- "border-radius": "5px",
32
- "cursor": "pointer",
33
- },
34
- "label": {
35
- "color": "#fff",
36
- },
37
- }
38
-
39
- gr.Interface(
40
- fn=classify_emotion,
41
  inputs="textbox",
42
- outputs="text",
43
- title=title,
44
  theme=theme,
45
- description=description,
46
- examples=examples,
47
- ).launch()
 
 
 
 
 
 
 
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()