zoya23 commited on
Commit
9db2de0
·
verified ·
1 Parent(s): fec6ac6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -33
app.py CHANGED
@@ -1,38 +1,49 @@
1
  import streamlit as st
2
  import transformers
3
- from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
 
 
 
 
 
4
 
5
  # Title
6
- st.markdown("<h1 style='text-align: center; color: black;'>Text Summarization App</h1>", unsafe_allow_html=True)
7
- st.markdown("---")
8
-
9
- # Model Selection
10
- model_choice = st.selectbox("Select a Summarization Model", ["BART", "T5", "PEGASUS"])
11
-
12
- # Load model and tokenizer
13
- @st.cache_resource
14
- def load_model(model_name):
15
- tokenizer = AutoTokenizer.from_pretrained(model_name)
16
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
17
- return pipeline("summarization", model=model, tokenizer=tokenizer)
18
-
19
- # Map choices to model names or paths
20
- model_map = {
21
- "BART": "facebook/bart-large-cnn",
22
- "T5": "t5-small",
23
- "PEGASUS": "google/pegasus-cnn_dailymail"
24
- }
25
-
26
- # Text Input
27
- text_input = st.text_area("Enter the text you want to summarize:", height=300)
28
-
29
- # Button to generate summary
30
- if st.button("Summarize"):
31
- if not text_input.strip():
32
- st.warning("Please enter some text!")
 
 
 
 
 
 
 
 
 
 
33
  else:
34
- summarizer = load_model(model_map[model_choice])
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**.")