Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import
|
4 |
|
5 |
-
#
|
6 |
sentiment_model = pipeline("sentiment-analysis")
|
7 |
summarizer_model = pipeline("summarization")
|
8 |
-
# Text-to-Speech using pyttsx3 (offline TTS engine)
|
9 |
-
engine = pyttsx3.init()
|
10 |
|
11 |
-
#
|
12 |
def analyze_sentiment(text):
|
13 |
result = sentiment_model(text)[0]
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
def summarize_text(text):
|
18 |
summary = summarizer_model(text, max_length=60, min_length=15, do_sample=False)
|
19 |
return summary[0]['summary_text']
|
20 |
|
21 |
-
#
|
22 |
def text_to_speech(text):
|
23 |
-
filename = "output_audio.
|
24 |
-
|
25 |
-
|
26 |
return filename
|
27 |
|
28 |
-
#
|
29 |
with gr.Blocks() as demo:
|
30 |
-
gr.Markdown("## ๐ง NLP Tools: Sentiment | Summarization | Text-to-Speech")
|
31 |
-
|
32 |
with gr.Row():
|
33 |
-
input_text = gr.Textbox(label="Enter your text
|
34 |
|
35 |
with gr.Row():
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
with gr.Row():
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from gtts import gTTS
|
4 |
|
5 |
+
# ุชุญู
ูู ุงููู
ุงุฐุฌ ู
ู Hugging Face
|
6 |
sentiment_model = pipeline("sentiment-analysis")
|
7 |
summarizer_model = pipeline("summarization")
|
|
|
|
|
8 |
|
9 |
+
# ุฏุงูุฉ ุชุญููู ุงูู
ุดุงุนุฑ
|
10 |
def analyze_sentiment(text):
|
11 |
result = sentiment_model(text)[0]
|
12 |
+
label = result['label']
|
13 |
+
score = round(result['score'], 2)
|
14 |
+
return f"Sentiment: {label}, Confidence: {score}"
|
15 |
|
16 |
+
# ุฏุงูุฉ ุงูุชูุฎูุต
|
17 |
def summarize_text(text):
|
18 |
summary = summarizer_model(text, max_length=60, min_length=15, do_sample=False)
|
19 |
return summary[0]['summary_text']
|
20 |
|
21 |
+
# ุฏุงูุฉ ุชุญููู ุงููุต ุฅูู ุตูุช
|
22 |
def text_to_speech(text):
|
23 |
+
filename = "output_audio.mp3"
|
24 |
+
tts = gTTS(text)
|
25 |
+
tts.save(filename)
|
26 |
return filename
|
27 |
|
28 |
+
# ุจูุงุก ุงููุงุฌูุฉ ุจู Gradio
|
29 |
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("## ๐ง NLP Tools: Sentiment Analysis | Summarization | Text-to-Speech")
|
31 |
+
|
32 |
with gr.Row():
|
33 |
+
input_text = gr.Textbox(label="Enter your text", lines=6, placeholder="Type or paste your text here...")
|
34 |
|
35 |
with gr.Row():
|
36 |
+
btn_sentiment = gr.Button("๐ Analyze Sentiment")
|
37 |
+
btn_summarize = gr.Button("๐ Summarize")
|
38 |
+
btn_tts = gr.Button("๐ Convert to Speech")
|
39 |
|
40 |
with gr.Row():
|
41 |
+
output_sentiment = gr.Textbox(label="Sentiment Result")
|
42 |
+
output_summary = gr.Textbox(label="Summary")
|
43 |
+
output_audio = gr.Audio(label="Text to Speech Output")
|
44 |
|
45 |
+
btn_sentiment.click(analyze_sentiment, inputs=input_text, outputs=output_sentiment)
|
46 |
+
btn_summarize.click(summarize_text, inputs=input_text, outputs=output_summary)
|
47 |
+
btn_tts.click(text_to_speech, inputs=input_text, outputs=output_audio)
|
48 |
|
49 |
demo.launch()
|