bharathi212 commited on
Commit
4a46682
·
verified ·
1 Parent(s): 8f58e3c

requirements.txt

Browse files

transformers
gradio
torch

Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load summarization models
5
+ models = {
6
+ "BART Large CNN": pipeline("summarization", model="facebook/bart-large-cnn"),
7
+ "T5 Small": pipeline("summarization", model="t5-small")
8
+ }
9
+
10
+ # Sentiment analysis pipeline
11
+ sentiment_analyzer = pipeline("sentiment-analysis")
12
+
13
+ def summarize_compare(text):
14
+ summaries = {}
15
+ sentiments = {}
16
+
17
+ for model_name, summarizer in models.items():
18
+ summary = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
19
+ sentiment = sentiment_analyzer(summary)[0]
20
+ summaries[model_name] = summary
21
+ sentiments[model_name] = f"{sentiment['label']} ({round(sentiment['score'], 2)})"
22
+
23
+ return summaries["BART Large CNN"], sentiments["BART Large CNN"], summaries["T5 Small"], sentiments["T5 Small"]
24
+
25
+ demo = gr.Interface(
26
+ fn=summarize_compare,
27
+ inputs=gr.Textbox(lines=10, placeholder="Paste your text here..."),
28
+ outputs=[
29
+ gr.Textbox(label="BART Large CNN Summary"),
30
+ gr.Textbox(label="BART Large CNN Sentiment"),
31
+ gr.Textbox(label="T5 Small Summary"),
32
+ gr.Textbox(label="T5 Small Sentiment")
33
+ ],
34
+ title="Multi-Model Text Summarizer + Sentiment Analyzer",
35
+ description="Compare summaries from multiple models and see the sentiment of each summary."
36
+ )
37
+
38
+ demo.launch()