Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,49 @@
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
3 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Title
|
6 |
-
st.markdown("<h1 style='text-align: center;
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
"
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
if
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
else:
|
34 |
-
|
35 |
-
summary = summarizer(text_input, max_length=150, min_length=40, do_sample=False)
|
36 |
-
|
37 |
-
st.markdown("### Summary:")
|
38 |
-
st.success(summary[0]['summary_text'])
|
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
3 |
+
from transformers import pipeline
|
4 |
+
from keybert import KeyBERT
|
5 |
+
|
6 |
+
# Load summarizer and keyword model
|
7 |
+
summarizer_bart = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
+
kw_model = KeyBERT()
|
9 |
|
10 |
# Title
|
11 |
+
st.markdown("<h1 style='text-align: center;'>Text Summarization App</h1>", unsafe_allow_html=True)
|
12 |
+
|
13 |
+
# Modes
|
14 |
+
mode = st.radio("Modes", ["Paragraph", "Bullet Points", "Custom"], horizontal=True)
|
15 |
+
|
16 |
+
# Summary length
|
17 |
+
length = st.slider("Summary Length", 1, 2, 1, label_visibility="collapsed")
|
18 |
+
summary_type = "Short" if length == 1 else "Long"
|
19 |
+
st.write(f"Summary Length: **{summary_type}**")
|
20 |
+
|
21 |
+
# Layout
|
22 |
+
col1, col2 = st.columns(2)
|
23 |
+
|
24 |
+
with col1:
|
25 |
+
st.markdown("### Paste your text below:")
|
26 |
+
user_input = st.text_area("", height=300, placeholder="Paste job description or any paragraph...")
|
27 |
+
|
28 |
+
if user_input.strip():
|
29 |
+
# Extract keywords using KeyBERT
|
30 |
+
keywords = [kw[0] for kw in kw_model.extract_keywords(user_input, top_n=5)]
|
31 |
+
selected_keywords = st.multiselect("Select Keywords", keywords, default=keywords)
|
32 |
+
st.markdown(f"**{len(user_input.split())} words**")
|
33 |
+
|
34 |
+
if st.button("Summarize", use_container_width=True):
|
35 |
+
summary = summarizer_bart(user_input, max_length=150 if summary_type == "Short" else 250,
|
36 |
+
min_length=40, do_sample=False)[0]['summary_text']
|
37 |
+
st.session_state['summary'] = summary
|
38 |
+
else:
|
39 |
+
st.warning("Please enter some text.")
|
40 |
+
|
41 |
+
with col2:
|
42 |
+
st.markdown("### Summary")
|
43 |
+
if 'summary' in st.session_state:
|
44 |
+
st.success(st.session_state['summary'])
|
45 |
+
st.markdown(f"1 sentence • {len(st.session_state['summary'].split())} words")
|
46 |
+
st.button("Paraphrase Summary")
|
47 |
+
st.download_button("📥 Download Summary", st.session_state['summary'], file_name="summary.txt")
|
48 |
else:
|
49 |
+
st.info("Your summary will appear here after clicking **Summarize**.")
|
|
|
|
|
|
|
|