Spaces:
Runtime error
Runtime error
Commit ·
c795f35
1
Parent(s): 8032f8d
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,25 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import BartTokenizer, BartForConditionalGeneration
|
| 3 |
+
from rouge_score import rouge_scorer
|
| 4 |
|
| 5 |
+
# Load BART model and tokenizer
|
| 6 |
+
model_name = "facebook/bart-large-cnn"
|
| 7 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Load ROUGE scorer
|
| 11 |
+
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
|
| 12 |
+
|
| 13 |
+
st.title("Text Summarization with BART Model")
|
| 14 |
+
input_text = st.text_area("Enter an article to summarize:")
|
| 15 |
+
|
| 16 |
+
if st.button("Generate Summary"):
|
| 17 |
+
if input_text.strip() != "":
|
| 18 |
+
# Generate summary using the model
|
| 19 |
+
inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=True)
|
| 20 |
+
summary_ids = model.generate(inputs["input_ids"], max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 21 |
+
generated_summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 22 |
+
|
| 23 |
+
# Display generated summary
|
| 24 |
+
st.subheader("Generated Summary:")
|
| 25 |
+
st.write(generated_summary)
|