Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
# Load sentiment analysis model
|
5 |
-
|
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
|
15 |
-
# Get sentiment
|
16 |
-
|
17 |
|
18 |
# Adjust speech synthesis parameters based on sentiment
|
19 |
-
# You can customize this part based on the sentiment
|
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
|
25 |
|
26 |
# Replace the following line with your desired text-to-speech model and parameters.
|
27 |
-
speech_output = f"This is a {
|
28 |
|
29 |
return speech_output
|
30 |
|
31 |
tts_demo = gr.Interface(
|
32 |
-
fn=
|
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,
|