Spaces:
Runtime error
Runtime error
Meshal Falah
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
warnings.filterwarnings('ignore')
|
| 3 |
+
import transformers
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
from TTS.api import TTS
|
| 7 |
+
|
| 8 |
+
#1 - Sentiment Analysis Tab:
|
| 9 |
+
sentiment =pipeline("text-classification", model="tabularisai/multilingual-sentiment-analysis")
|
| 10 |
+
|
| 11 |
+
def get_sentiment(text):
|
| 12 |
+
result = sentiment(text)
|
| 13 |
+
label = result[0]['label']
|
| 14 |
+
score = result[0]['score']
|
| 15 |
+
return label, score
|
| 16 |
+
|
| 17 |
+
#2 - Summarization Tab:
|
| 18 |
+
summary_pipe = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 19 |
+
|
| 20 |
+
def get_summary(text):
|
| 21 |
+
result = summary_pipe(text[:1000])
|
| 22 |
+
return result[0]['summary_text']
|
| 23 |
+
|
| 24 |
+
#3 - text-to-Speech Tab:
|
| 25 |
+
tts_model= TTS("tts_models/en/ljspeech/tacotron2-DDC", gpu=False)
|
| 26 |
+
|
| 27 |
+
def text_to_speech(text):
|
| 28 |
+
filename = "output.wav"
|
| 29 |
+
tts_model.tts_to_file(text=text, file_path=filename)
|
| 30 |
+
return filename
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as AI_applications:
|
| 34 |
+
with gr.Tab("Sentiment Analysis"):
|
| 35 |
+
sentiment_input = gr.Textbox(label="Enter Text")
|
| 36 |
+
output_label = gr.Text(label="Sentiment Label")
|
| 37 |
+
output_score = gr.Text(label="Confidence Score")
|
| 38 |
+
analyze_button = gr.Button("Analyze Sentiment")
|
| 39 |
+
analyze_button.click(fn=get_sentiment,inputs=sentiment_input ,outputs=[output_label, output_score])
|
| 40 |
+
|
| 41 |
+
with gr.Tab("Summarization"):
|
| 42 |
+
|
| 43 |
+
summary_input = gr.Textbox(label="Enter Long Text", lines=10, placeholder="Paste your text here...")
|
| 44 |
+
output_summary = gr.Textbox(label="Summary", lines=5)
|
| 45 |
+
summarize_btn = gr.Button("Summarize")
|
| 46 |
+
summarize_btn .click(fn=get_summary, inputs=summary_input, outputs=output_summary)
|
| 47 |
+
|
| 48 |
+
with gr.Tab("Text to Speech"):
|
| 49 |
+
|
| 50 |
+
tts_input = gr.Textbox(label="Enter Text to Speak", lines=4, placeholder="Type something...")
|
| 51 |
+
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
| 52 |
+
generate_btn = gr.Button("Generate Speech")
|
| 53 |
+
generate_btn.click(fn=text_to_speech, inputs=tts_input , outputs=output_audio)
|
| 54 |
+
|
| 55 |
+
AI_applications.launch()
|