Spaces:
Sleeping
Sleeping
File size: 1,424 Bytes
13d8ce0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from transformers import pipeline
import gradio as gr
from gtts import gTTS
# Sentiment Analysis
sentiment = pipeline("sentiment-analysis")
def get_sentiment(text):
result = sentiment(text)[0]
return result["label"], result["score"]
sentiment_tab = gr.Interface(
fn=get_sentiment,
inputs=gr.Textbox(label="Enter your review: "),
outputs=[gr.Textbox(label="Sentiment"), gr.Number(label="Score")],
title="Reviews Sentiment Analysis"
)
# Summarization
summarize = pipeline("summarization", model="facebook/bart-large-cnn")
def summarization(text):
return summarize(text)[0]["summary_text"]
summary_tab = gr.Interface(
fn=summarization,
inputs=gr.Textbox(label="Enter your text: "),
outputs=gr.Textbox(label="Summarization"),
title="Summarizer"
)
# Text to Speech
def convert(text):
tts = gTTS(text)
file_path = "output.mp3"
tts.save(file_path)
return file_path
text_to_speech_tab = gr.Interface(
fn=convert,
inputs=gr.Textbox(label="Enter your text to turn into audio:"),
outputs=gr.Audio(label="Generated Audio", type="filepath"),
title="Text to Speech Converter"
)
# Combine all in Tabs
demo = gr.TabbedInterface(
[sentiment_tab, summary_tab, text_to_speech_tab],
["Sentiment", "Summarizer", "Text-To-Speech"],
theme="soft"
)
if __name__ == "__main__":
demo.launch()
|