Spaces:
Sleeping
Sleeping
| 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() | |