zoya23 commited on
Commit
040b456
·
verified ·
1 Parent(s): d46e01c

Update app.py

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