Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import PegasusForConditionalGeneration, PegasusTokenizer, pipeline
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model = PegasusForConditionalGeneration.from_pretrained("fatihfauzan26/PEGASUS_liputan6")
|
6 |
+
tokenizer = PegasusTokenizer.from_pretrained("google/pegasus-cnn_dailymail")
|
7 |
+
|
8 |
+
# Initialize the summarization pipeline
|
9 |
+
summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
10 |
+
|
11 |
+
# Streamlit interface
|
12 |
+
st.title("Summarization App using PEGASUS")
|
13 |
+
|
14 |
+
# Input article for summarization
|
15 |
+
sample_article = st.text_area('Enter the article you want to summarize', height=300)
|
16 |
+
|
17 |
+
if sample_article:
|
18 |
+
# Generate summary
|
19 |
+
input_ids = tokenizer.encode(sample_article, return_tensors='pt')
|
20 |
+
summary_ids = model.generate(input_ids,
|
21 |
+
min_length=30,
|
22 |
+
max_length=128,
|
23 |
+
num_beams=8,
|
24 |
+
repetition_penalty=2.0,
|
25 |
+
length_penalty=0.8,
|
26 |
+
early_stopping=True,
|
27 |
+
no_repeat_ngram_size=2,
|
28 |
+
use_cache=True,
|
29 |
+
do_sample=True,
|
30 |
+
temperature=1.2,
|
31 |
+
top_k=50,
|
32 |
+
top_p=0.95)
|
33 |
+
|
34 |
+
# Decode the summary
|
35 |
+
summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
36 |
+
|
37 |
+
# Display results
|
38 |
+
st.subheader("Summary")
|
39 |
+
st.write(summary_text)
|