Siri23 commited on
Commit
691f546
·
verified ·
1 Parent(s): 88d3e6e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load model and tokenizer
5
+ @st.cache_resource()
6
+ def load_model():
7
+ tokenizer = AutoTokenizer.from_pretrained("google/pegasus-xsum")
8
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/pegasus-xsum")
9
+ return tokenizer, model
10
+
11
+ tokenizer, model = load_model()
12
+
13
+ st.title("Text Summarization with Pegasus-XSum")
14
+ st.write("Enter text below and get a summarized version using the Pegasus model.")
15
+
16
+ # User input
17
+ text_input = st.text_area("Enter text to summarize:", "")
18
+
19
+ if st.button("Summarize"):
20
+ if text_input:
21
+ # Tokenize input
22
+ inputs = tokenizer(text_input, return_tensors="pt", truncation=True, max_length=512)
23
+
24
+ # Generate summary
25
+ summary_ids = model.generate(**inputs, max_length=60, min_length=10, length_penalty=2.0, num_beams=4)
26
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
27
+
28
+ # Display summary
29
+ st.subheader("Summary:")
30
+ st.write(summary)
31
+ else:
32
+ st.warning("Please enter some text to summarize.")