Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,62 @@
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
3 |
-
import keybert
|
4 |
from transformers import pipeline
|
5 |
-
from keybert import KeyBERT
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
# Title
|
12 |
st.markdown("<h1 style='text-align: center;'>Text Summarization App</h1>", unsafe_allow_html=True)
|
13 |
|
14 |
-
#
|
15 |
mode = st.radio("Modes", ["Paragraph", "Bullet Points", "Custom"], horizontal=True)
|
|
|
|
|
|
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
summary_type = "Short" if length == 1 else "Long"
|
20 |
-
st.write(f"Summary Length: **{summary_type}**")
|
21 |
|
22 |
-
#
|
23 |
col1, col2 = st.columns(2)
|
24 |
|
|
|
25 |
with col1:
|
26 |
-
st.markdown("###
|
27 |
-
user_input = st.text_area("", height=300, placeholder="Paste job description or
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
if
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
with col2:
|
43 |
st.markdown("### Summary")
|
44 |
-
if
|
45 |
-
st.success(st.session_state[
|
46 |
-
|
|
|
47 |
st.button("Paraphrase Summary")
|
48 |
-
st.download_button("📥 Download Summary", st.session_state[
|
49 |
else:
|
50 |
-
st.info("Your summary will appear here
|
|
|
1 |
import streamlit as st
|
2 |
import transformers
|
|
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
+
# Set up model paths (you can later replace these with fine-tuned model folders)
|
6 |
+
model_map = {
|
7 |
+
"BART": "facebook/bart-large-cnn",
|
8 |
+
"T5": "t5-small",
|
9 |
+
"PEGASUS": "google/pegasus-cnn_dailymail"
|
10 |
+
}
|
11 |
|
12 |
+
# App Title
|
13 |
st.markdown("<h1 style='text-align: center;'>Text Summarization App</h1>", unsafe_allow_html=True)
|
14 |
|
15 |
+
# UI: Mode and Length controls
|
16 |
mode = st.radio("Modes", ["Paragraph", "Bullet Points", "Custom"], horizontal=True)
|
17 |
+
length_slider = st.slider("Summary Length", 1, 2, 1, label_visibility="collapsed")
|
18 |
+
length_label = "Short" if length_slider == 1 else "Long"
|
19 |
+
st.markdown(f"Summary Length: **{length_label}**")
|
20 |
|
21 |
+
# Model selection
|
22 |
+
model_choice = st.selectbox("Choose Summarization Model", ["BART", "T5", "PEGASUS"])
|
|
|
|
|
23 |
|
24 |
+
# 2-column layout
|
25 |
col1, col2 = st.columns(2)
|
26 |
|
27 |
+
# Left Column: Input
|
28 |
with col1:
|
29 |
+
st.markdown("### Enter your text:")
|
30 |
+
user_input = st.text_area("", height=300, placeholder="Paste your job description or content here...")
|
31 |
+
|
32 |
+
# Word count
|
33 |
+
word_count = len(user_input.split())
|
34 |
+
st.markdown(f"**{word_count} words**")
|
35 |
+
|
36 |
+
# Summarize Button
|
37 |
+
if st.button("Summarize", use_container_width=True):
|
38 |
+
if not user_input.strip():
|
39 |
+
st.warning("Please enter text to summarize.")
|
40 |
+
else:
|
41 |
+
# Load model
|
42 |
+
summarizer = pipeline("summarization", model=model_map[model_choice])
|
43 |
+
|
44 |
+
# Set length dynamically
|
45 |
+
max_len = 150 if length_label == "Short" else 300
|
46 |
+
min_len = 40
|
47 |
+
|
48 |
+
# Generate summary
|
49 |
+
summary = summarizer(user_input, max_length=max_len, min_length=min_len, do_sample=False)[0]['summary_text']
|
50 |
+
st.session_state["summary"] = summary
|
51 |
+
|
52 |
+
# Right Column: Output
|
53 |
with col2:
|
54 |
st.markdown("### Summary")
|
55 |
+
if "summary" in st.session_state:
|
56 |
+
st.success(st.session_state["summary"])
|
57 |
+
summary_words = len(st.session_state["summary"].split())
|
58 |
+
st.markdown(f"📝 1 sentence • {summary_words} words")
|
59 |
st.button("Paraphrase Summary")
|
60 |
+
st.download_button("📥 Download Summary", st.session_state["summary"], file_name="summary.txt")
|
61 |
else:
|
62 |
+
st.info("Your summary will appear here.")
|