Vishaltiwari2019 commited on
Commit
ff78663
·
verified ·
1 Parent(s): 622dc35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -44
app.py CHANGED
@@ -1,46 +1,47 @@
1
  import gradio as gr
2
- import nltk
3
-
4
- # Download the VADER lexicon
5
- nltk.download('vader_lexicon')
6
-
7
- # Rest of your code
8
- from nltk.sentiment import SentimentIntensityAnalyzer
9
-
10
- # Text to Speech
11
- title = "Text to Speech with Sentiment Analysis"
12
- tts_examples = [
13
- "I love learning machine learning",
14
- "How do you do?",
15
- ]
16
-
17
- def get_sentiment(text):
18
- # Get sentiment score
19
- sia = SentimentIntensityAnalyzer()
20
- sentiment_score = sia.polarity_scores(text)["compound"]
21
-
22
- # Adjust speech synthesis parameters based on sentiment
23
- # You can customize this part based on the sentiment score.
24
-
25
- # For example, if sentiment is positive, use a happy tone; if negative, use a sad tone.
26
-
27
- # Modify the speech synthesis model and parameters accordingly.
28
- # Use the sentiment_score to adjust the tone.
29
-
30
- # Replace the following line with your desired text-to-speech model and parameters.
31
- speech_output = f"This is a text with sentiment score {sentiment_score}: {text}"
32
-
33
- return {"audio": speech_output}
34
-
35
- tts_demo = gr.Interface(
36
- fn=get_sentiment,
37
- inputs="text",
38
- outputs="audio",
39
- examples=tts_examples,
 
 
 
40
  title=title,
41
- description="Give me something to say with sentiment analysis!",
42
- )
43
-
44
- demo = gr.TabbedInterface([tts_demo], ["Text to speech with sentiment"])
45
- if __name__ == "__main__":
46
- demo.launch()
 
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()