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