Vishaltiwari2019 commited on
Commit
7982942
·
verified ·
1 Parent(s): 71ff0b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
  # Load sentiment analysis model
5
- sentiment_analyzer = pipeline("sentiment-analysis")
6
 
7
  # Text to Speech
8
  title = "Text to Speech with Sentiment Analysis"
@@ -11,25 +11,25 @@ tts_examples = [
11
  "How do you do?",
12
  ]
13
 
14
- def tts_with_sentiment(text):
15
- # Get sentiment
16
- sentiment_result = sentiment_analyzer(text)[0]
17
 
18
  # Adjust speech synthesis parameters based on sentiment
19
- # You can customize this part based on the sentiment labels returned by your sentiment analysis model
20
 
21
  # For example, if sentiment is positive, use a happy tone; if negative, use a sad tone.
22
 
23
  # Modify the speech synthesis model and parameters accordingly.
24
- # Use the sentiment_result['label'] to access sentiment label (positive/negative/neutral).
25
 
26
  # Replace the following line with your desired text-to-speech model and parameters.
27
- speech_output = f"This is a {sentiment_result['label']} sentiment: {text}"
28
 
29
  return speech_output
30
 
31
  tts_demo = gr.Interface(
32
- fn=tts_with_sentiment,
33
  inputs="text",
34
  outputs="audio",
35
  examples=tts_examples,
 
1
  import gradio as gr
2
+ from nltk.sentiment import SentimentIntensityAnalyzer
3
 
4
  # Load sentiment analysis model
5
+ sia = SentimentIntensityAnalyzer()
6
 
7
  # Text to Speech
8
  title = "Text to Speech with Sentiment Analysis"
 
11
  "How do you do?",
12
  ]
13
 
14
+ def get_sentiment(text):
15
+ # Get sentiment score
16
+ sentiment_score = sia.polarity_scores(text)["compound"]
17
 
18
  # Adjust speech synthesis parameters based on sentiment
19
+ # You can customize this part based on the sentiment score.
20
 
21
  # For example, if sentiment is positive, use a happy tone; if negative, use a sad tone.
22
 
23
  # Modify the speech synthesis model and parameters accordingly.
24
+ # Use the sentiment_score to adjust the tone.
25
 
26
  # Replace the following line with your desired text-to-speech model and parameters.
27
+ speech_output = f"This is a text with sentiment score {sentiment_score}: {text}"
28
 
29
  return speech_output
30
 
31
  tts_demo = gr.Interface(
32
+ fn=get_sentiment,
33
  inputs="text",
34
  outputs="audio",
35
  examples=tts_examples,