zoya23 commited on
Commit
50c6f53
·
verified ·
1 Parent(s): 8a8845e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "pavuluriashwitha/Bart_model",
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.")