mahesh1209's picture
Create app.py
89c2b90 verified
raw
history blame
1.29 kB
import gradio as gr
from transformers import pipeline
from textblob import TextBlob
# Load summarization pipeline
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
def analyze(text):
if not text.strip():
return "⚠️ No input provided.", "Polarity: N/A | Subjectivity: N/A"
try:
summary = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
except Exception as e:
summary = f"⚠️ Summarization failed: {str(e)}"
sentiment = TextBlob(text).sentiment
polarity = f"Polarity: {sentiment.polarity:.2f}"
subjectivity = f"Subjectivity: {sentiment.subjectivity:.2f}"
return summary, polarity + " | " + subjectivity
with gr.Blocks() as demo:
gr.Markdown("## ✨ Text Summarizer & Sentiment Analyzer")
with gr.Row():
with gr.Column():
input_text = gr.Textbox(lines=10, label="Enter your text", placeholder="Paste your article or paragraph here...")
analyze_btn = gr.Button("Analyze")
with gr.Column():
output_summary = gr.Textbox(label="Summary")
output_sentiment = gr.Textbox(label="Sentiment")
analyze_btn.click(fn=analyze, inputs=input_text, outputs=[output_summary, output_sentiment])
demo.launch()