Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load pre-trained model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("avisena/bart-base-job-info-summarizer")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("avisena/bart-base-job-info-summarizer")
|
7 |
+
|
8 |
+
# Streamlit app
|
9 |
+
st.title("Text Summarization App")
|
10 |
+
|
11 |
+
# Text input
|
12 |
+
text_input = st.text_area("Enter the text to summarize:", height=200)
|
13 |
+
|
14 |
+
# Summarize button
|
15 |
+
if st.button("Summarize"):
|
16 |
+
if text_input:
|
17 |
+
# Tokenize input text
|
18 |
+
inputs = tokenizer.encode(text_input, return_tensors="pt", max_length=1024, truncation='do_not_truncate')
|
19 |
+
|
20 |
+
# Generate summary
|
21 |
+
summary_ids = model.generate(
|
22 |
+
inputs,
|
23 |
+
max_length=200, # Maximum length of the summary
|
24 |
+
min_length=30, # Minimum length of the summary
|
25 |
+
length_penalty=0.98, # Penalty for longer sequences
|
26 |
+
num_beams=6, # Number of beams for beam search
|
27 |
+
top_p=3.7,
|
28 |
+
early_stopping=True,
|
29 |
+
temperature=1.4,
|
30 |
+
do_sample=True
|
31 |
+
)
|
32 |
+
|
33 |
+
# Decode summary
|
34 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True, max_length=512, truncation='do_not_truncate')
|
35 |
+
|
36 |
+
# Display the summarized text
|
37 |
+
st.subheader("Summary")
|
38 |
+
st.write(summary)
|
39 |
+
else:
|
40 |
+
st.warning("Please enter some text to summarize.")
|