Vishaltiwari2019 commited on
Commit
ab11305
·
verified ·
1 Parent(s): 09094bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -1,23 +1,42 @@
1
  import gradio as gr
 
2
 
3
- #################################################################
4
- #1: Text to Speech
5
- #import gradio as gr
6
- title = "Text to Speech Translation"
 
7
  tts_examples = [
8
  "I love learning machine learning",
9
  "How do you do?",
10
  ]
11
- tts_demo = gr.Interface.load(
12
- "huggingface/facebook/fastspeech2-en-ljspeech",
13
- title = title,
14
- examples=tts_examples,
15
- description="Give me something to say!",
16
- )
17
 
 
 
 
 
 
 
 
 
18
 
19
- #################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- demo = gr.TabbedInterface([tts_demo], ["Text to speech"])
22
  if __name__ == "__main__":
23
- demo.launch()
 
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"
9
  tts_examples = [
10
  "I love learning machine learning",
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,
36
+ title=title,
37
+ description="Give me something to say with sentiment analysis!",
38
+ )
39
 
40
+ demo = gr.TabbedInterface([tts_demo], ["Text to speech with sentiment"])
41
  if __name__ == "__main__":
42
+ demo.launch()