manasagangotri commited on
Commit
379e449
·
verified ·
1 Parent(s): f659be6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import PegasusTokenizer, PegasusForConditionalGeneration
3
+
4
+ # Load Pegasus model and tokenizer
5
+ model_name = "google/pegasus-xsum"
6
+ tokenizer = PegasusTokenizer.from_pretrained(model_name)
7
+ model = PegasusForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ # Function to summarize text
10
+ def summarize_text(text):
11
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)
12
+ summary_ids = model.generate(inputs.input_ids, max_length=128, min_length=30, length_penalty=2.0, num_beams=5)
13
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
14
+ return summary
15
+
16
+ # Gradio interface
17
+ iface = gr.Interface(fn=summarize_text,
18
+ inputs=gr.Textbox(label="Enter text to summarize"),
19
+ outputs=gr.Textbox(label="Summary"),
20
+ title="Pegasus Text Summarizer",
21
+ description="This AI agent summarizes long text using the Pegasus model.")
22
+
23
+ # Launch the app
24
+ iface.launch()