Spaces:
Runtime error
Runtime error
| import warnings | |
| warnings.filterwarnings('ignore') | |
| import transformers | |
| import gradio as gr | |
| from transformers import pipeline | |
| from TTS.api import TTS | |
| #1 - Sentiment Analysis Tab: | |
| sentiment =pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis") | |
| def get_sentiment(text): | |
| result = sentiment(text) | |
| label = result[0]['label'] | |
| score = result[0]['score'] | |
| return label, score | |
| #2 - Summarization Tab: | |
| summary_pipe = pipeline("summarization", model="google/pegasus-cnn_dailymail") | |
| def get_summary(text): | |
| max_len = int(len(text.split()) * 0.35) | |
| max_len = max(5, min(max_len, 512)) | |
| min_len = int(len(text.split()) * 0.2) | |
| result = summary_pipe(text, max_length=max_len, min_length=min_len, do_sample=False) | |
| return result[0]['summary_text'] | |
| #3 - text-to-Speech Tab: | |
| tts_model= TTS("tts_models/en/ljspeech/tacotron2-DDC", gpu=False) | |
| def text_to_speech(text): | |
| filename = "output.wav" | |
| tts_model.tts_to_file(text=text, file_path=filename) | |
| return filename | |
| with gr.Blocks() as AI_applications: | |
| with gr.Tab("Sentiment Analysis"): | |
| sentiment_input = gr.Textbox(label="Enter Text") | |
| output_label = gr.Text(label="Sentiment Label") | |
| output_score = gr.Text(label="Confidence Score") | |
| analyze_button = gr.Button("Analyze Sentiment") | |
| analyze_button.click(fn=get_sentiment,inputs=sentiment_input ,outputs=[output_label, output_score]) | |
| with gr.Tab("Summarization"): | |
| summary_input = gr.Textbox(label="Enter Long Text", lines=10, placeholder="Paste your text here...") | |
| output_summary = gr.Textbox(label="Summary", lines=5) | |
| summarize_btn = gr.Button("Summarize") | |
| summarize_btn .click(fn=get_summary, inputs=summary_input, outputs=output_summary) | |
| with gr.Tab("Text to Speech"): | |
| tts_input = gr.Textbox(label="Enter Text to Speak", lines=4, placeholder="Type something...") | |
| output_audio = gr.Audio(label="Generated Speech", type="filepath") | |
| generate_btn = gr.Button("Generate Speech") | |
| generate_btn.click(fn=text_to_speech, inputs=tts_input , outputs=output_audio) | |
| AI_applications.launch() |