Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# Load sentiment analysis model | |
sentiment_analyzer = pipeline("sentiment-analysis") | |
# Text to Speech | |
title = "Text to Speech with Sentiment Analysis" | |
tts_examples = [ | |
"I love learning machine learning", | |
"How do you do?", | |
] | |
def tts_with_sentiment(text): | |
# Get sentiment | |
sentiment_result = sentiment_analyzer(text)[0] | |
# Adjust speech synthesis parameters based on sentiment | |
# You can customize this part based on the sentiment labels returned by your sentiment analysis model | |
# For example, if sentiment is positive, use a happy tone; if negative, use a sad tone. | |
# Modify the speech synthesis model and parameters accordingly. | |
# Use the sentiment_result['label'] to access sentiment label (positive/negative/neutral). | |
# Replace the following line with your desired text-to-speech model and parameters. | |
speech_output = f"This is a {sentiment_result['label']} sentiment: {text}" | |
return speech_output | |
tts_demo = gr.Interface( | |
fn=tts_with_sentiment, | |
inputs="text", | |
outputs="audio", | |
examples=tts_examples, | |
title=title, | |
description="Give me something to say with sentiment analysis!", | |
) | |
demo = gr.TabbedInterface([tts_demo], ["Text to speech with sentiment"]) | |
if __name__ == "__main__": | |
demo.launch() | |