File size: 1,727 Bytes
785faa9
ff78663
 
23610b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ff78663
23610b0
 
ff78663
23610b0
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
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
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from transformers import pipeline

# Load text-to-speech model
tts_title = "Text to Speech Translation"
tts_examples = ["I love learning machine learning", "How do you do?"]
tts_demo = gr.Interface.load(
    "huggingface/facebook/fastspeech2-en-ljspeech",
    title=tts_title,
    examples=tts_examples,
    description="Give me something to say!",
)

# Load emotion classification model
emotion_model_checkpoint = "MuntasirHossain/RoBERTa-base-finetuned-emotion"
emotion_model = pipeline("text-classification", model=emotion_model_checkpoint)

def classify_emotion_and_speech(text):
    # Emotion classification
    emotion_label = emotion_model(text)[0]["label"]

    # Adjust speech synthesis parameters based on emotion_label.
    # Customize this part based on the emotion_label.

    # Replace the following line with your desired text-to-speech model and parameters.
    speech_output = f"Emotion: {emotion_label}, Text: {text}"

    return {"emotion_label": emotion_label, "audio": speech_output}

emotion_title = "Texts Expressing Emotion with Speech"
emotion_description = "This AI model classifies texts expressing human emotion and converts them into speech."
emotion_examples = [["He is very happy today", "Free Palestine"]]

combined_demo = gr.Interface(
    fn=classify_emotion_and_speech,
    inputs="textbox",
    outputs=["text", "audio"],
    title=emotion_title,
    theme=theme,
    description=emotion_description,
    examples=emotion_examples,
)

# Combine both demos into a Tabbed Interface
combined_demo_tabbed = gr.TabbedInterface([tts_demo, combined_demo], ["Text to Speech", "Texts Expressing Emotion with Speech"])

if __name__ == "__main__":
    combined_demo_tabbed.launch()