AIsumit123 commited on
Commit
1e418a0
·
verified ·
1 Parent(s): 72b542b

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. app.py +415 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use and official Python base image
2
+ FROM python:3.13
3
+ # Set the working directory inside container
4
+ WORKDIR /app
5
+ # Copy files into the container
6
+ COPY requirements.txt .
7
+ COPY app.py .
8
+ # Install python dependencies
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ # Expose the port for streamlit app
12
+ EXPOSE 8501
13
+
14
+ # Default command to run your app
15
+ CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # import streamlit as st
3
+ # from transformers import pipeline
4
+
5
+ # # ---- Load both models ----
6
+ # @st.cache_resource
7
+ # def load_summarizers():
8
+ # model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt" # your fine-tuned
9
+ # summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft)
10
+
11
+ # model_name_ft2 = "philschmid/flan-t5-base-samsum" # comparison fine-tuned
12
+ # summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2)
13
+
14
+ # model_name = "google/flan-t5-base" # pretrained
15
+ # summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)
16
+
17
+ # return summarizer_ft, summarizer_ft2, summarizer
18
+
19
+
20
+ # summarizer_ft, summarizer_ft2, summarizer = load_summarizers()
21
+
22
+ # # ---- Streamlit Page Config ----
23
+ # st.set_page_config(page_title="Conversation Summarizer", page_icon="🤖", layout="wide")
24
+
25
+ # # ---- Custom CSS for Styling ----
26
+ # st.markdown("""
27
+ # <style>
28
+ # /* Background gradient */
29
+ # .stApp {
30
+ # background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364);
31
+ # color: #f5f6f7;
32
+ # font-family: 'Segoe UI', sans-serif;
33
+ # }
34
+
35
+ # /* Title */
36
+ # h1, h2, h3 {
37
+ # text-align: center;
38
+ # color: #fdfdfd;
39
+ # }
40
+
41
+ # /* Subheader accent */
42
+ # h2, h3 {
43
+ # color: #e0e0e0;
44
+ # }
45
+
46
+ # /* Input box styling */
47
+ # textarea {
48
+ # border-radius: 12px !important;
49
+ # }
50
+
51
+ # /* Summary cards */
52
+ # .summary-card {
53
+ # background: rgba(255, 255, 255, 0.08);
54
+ # border-radius: 15px;
55
+ # padding: 20px;
56
+ # box-shadow: 0 0 10px rgba(255,255,255,0.05);
57
+ # transition: transform 0.2s ease-in-out;
58
+ # }
59
+ # .summary-card:hover {
60
+ # transform: scale(1.02);
61
+ # }
62
+
63
+ # /* Section divider */
64
+ # hr {
65
+ # border: none;
66
+ # height: 2px;
67
+ # background: linear-gradient(to right, #00c6ff, #0072ff);
68
+ # margin: 30px 0;
69
+ # }
70
+
71
+ # /* Sidebar */
72
+ # [data-testid="stSidebar"] {
73
+ # background-color: rgba(15, 25, 35, 0.95);
74
+
75
+ # }
76
+ # [data-testid="stSidebar"] * {
77
+ # color: white !important;
78
+ # }
79
+
80
+ # .stButton>button {
81
+ # background: linear-gradient(90deg, #00c6ff, #0072ff);
82
+ # color: white;
83
+ # border-radius: 8px;
84
+ # font-weight: bold;
85
+ # border: none;
86
+ # transition: 0.3s;
87
+ # }
88
+ # .stButton>button:hover {
89
+ # background: linear-gradient(90deg, #0072ff, #00c6ff);
90
+ # transform: translateY(-1px);
91
+ # }
92
+
93
+ # </style>
94
+ # """, unsafe_allow_html=True)
95
+
96
+
97
+ # # ---- Header Section ----
98
+ # st.markdown("<h1>🤖 Conversation Summarizer</h1>", unsafe_allow_html=True)
99
+ # st.markdown("<h3>✨ Compare Pretrained vs Fine-tuned FLAN-T5 Models ✨</h3>", unsafe_allow_html=True)
100
+ # st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.")
101
+
102
+ # # ---- Text Input ----
103
+ # input_text = st.text_area(
104
+ # "💬 Conversation Input:",
105
+ # height=250,
106
+ # placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...",
107
+ # )
108
+
109
+ # # ---- Sidebar ----
110
+ # st.sidebar.header("⚙️ Summary Settings")
111
+ # max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10)
112
+ # min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5)
113
+ # num_beams = st.sidebar.slider("Number of beams", 1, 8, 4)
114
+
115
+ # # ---- Generate Button ----
116
+ # if st.button("✨ Generate Summaries"):
117
+ # if input_text.strip():
118
+ # with st.spinner("🧠 Models are thinking..."):
119
+ # base_summary = summarizer(
120
+ # input_text,
121
+ # max_length=max_length,
122
+ # min_length=min_length,
123
+ # num_beams=num_beams,
124
+ # early_stopping=True,
125
+ # )[0]["summary_text"]
126
+
127
+ # ft_summary = summarizer_ft(
128
+ # input_text,
129
+ # max_length=max_length,
130
+ # min_length=min_length,
131
+ # num_beams=num_beams,
132
+ # early_stopping=True,
133
+ # )[0]["summary_text"]
134
+
135
+ # ft_summary2 = summarizer_ft2(
136
+ # input_text,
137
+ # max_length=max_length,
138
+ # min_length=min_length,
139
+ # num_beams=num_beams,
140
+ # early_stopping=True,
141
+ # )[0]["summary_text"]
142
+
143
+ # st.success("✅ Summaries Generated!")
144
+
145
+ # # ---- Display Results ----
146
+ # st.markdown("<hr>", unsafe_allow_html=True)
147
+ # col1, col2, col3 = st.columns(3)
148
+
149
+ # with col1:
150
+ # st.markdown('<div class="summary-card"><h3>🧠 Base Model</h3><p>{}</p></div>'.format(base_summary), unsafe_allow_html=True)
151
+ # with col2:
152
+ # st.markdown('<div class="summary-card"><h3>🚀 Fine-tuned (Yours)</h3><p>{}</p></div>'.format(ft_summary), unsafe_allow_html=True)
153
+ # with col3:
154
+ # st.markdown('<div class="summary-card"><h3>🔬 Fine-tuned (Reference)</h3><p>{}</p></div>'.format(ft_summary2), unsafe_allow_html=True)
155
+
156
+ # st.markdown("<hr>", unsafe_allow_html=True)
157
+ # else:
158
+ # st.warning("⚠️ Please enter a conversation to summarize.")
159
+
160
+ import streamlit as st
161
+ from transformers import pipeline
162
+
163
+ # ---- Load both models ----
164
+ @st.cache_resource
165
+ def load_summarizers():
166
+ model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt" # your fine-tuned
167
+ summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft)
168
+
169
+ model_name_ft2 = "philschmid/flan-t5-base-samsum" # comparison fine-tuned
170
+ summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2)
171
+
172
+ model_name = "google/flan-t5-base" # pretrained
173
+ summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)
174
+
175
+ return summarizer_ft, summarizer_ft2, summarizer
176
+
177
+
178
+ summarizer_ft, summarizer_ft2, summarizer = load_summarizers()
179
+
180
+ # ---- Streamlit Page Config ----
181
+ st.set_page_config(page_title="Conversation Summarizer", page_icon="🤖", layout="wide")
182
+
183
+ # ---- Custom CSS for Styling ----
184
+ st.markdown("""
185
+ <style>
186
+ /* Background gradient */
187
+ .stApp {
188
+ background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364);
189
+ color: #f5f6f7;
190
+ font-family: 'Segoe UI', sans-serif;
191
+ }
192
+
193
+ /* Title */
194
+ h1, h2, h3 {
195
+ text-align: center;
196
+ color: #fdfdfd;
197
+ }
198
+
199
+ /* Subheader accent */
200
+ h2, h3 {
201
+ color: #e0e0e0;
202
+ }
203
+
204
+ /* Input box styling */
205
+ textarea {
206
+ border-radius: 12px !important;
207
+ }
208
+
209
+ /* Summary cards */
210
+ .summary-card {
211
+ background: rgba(255, 255, 255, 0.08);
212
+ border-radius: 15px;
213
+ padding: 20px;
214
+ box-shadow: 0 0 10px rgba(255,255,255,0.05);
215
+ transition: transform 0.2s ease-in-out;
216
+ height: 100%;
217
+ }
218
+ .summary-card:hover {
219
+ transform: scale(1.02);
220
+ }
221
+
222
+ /* Section divider */
223
+ hr {
224
+ border: none;
225
+ height: 2px;
226
+ background: linear-gradient(to right, #00c6ff, #0072ff);
227
+ margin: 30px 0;
228
+ }
229
+
230
+ /* Sidebar Styling - FIXED TEXT COLOR */
231
+ [data-testid="stSidebar"] {
232
+ background-color: rgba(15, 25, 35, 0.95);
233
+ }
234
+
235
+ [data-testid="stSidebar"] * {
236
+ color: white !important;
237
+ }
238
+
239
+ [data-testid="stSidebar"] .stSlider label,
240
+ [data-testid="stSidebar"] .stSlider div,
241
+ [data-testid="stSidebar"] .stSlider span {
242
+ color: white !important;
243
+ }
244
+
245
+ /* Button styling */
246
+ .stButton>button {
247
+ background: linear-gradient(90deg, #00c6ff, #0072ff);
248
+ color: white;
249
+ border-radius: 8px;
250
+ font-weight: bold;
251
+ border: none;
252
+ transition: 0.3s;
253
+ width: 100%;
254
+ padding: 12px;
255
+ }
256
+ .stButton>button:hover {
257
+ background: linear-gradient(90deg, #0072ff, #00c6ff);
258
+ transform: translateY(-1px);
259
+ box-shadow: 0 4px 12px rgba(0, 114, 255, 0.3);
260
+ }
261
+
262
+ /* Stats cards */
263
+ .stats-card {
264
+ background: rgba(255, 255, 255, 0.05);
265
+ border-radius: 10px;
266
+ padding: 15px;
267
+ text-align: center;
268
+ margin: 5px;
269
+ }
270
+ </style>
271
+ """, unsafe_allow_html=True)
272
+
273
+ # ---- Header Section ----
274
+ st.markdown("<h1>🤖 Conversation Summarizer</h1>", unsafe_allow_html=True)
275
+ st.markdown("<h3>✨ Compare Pretrained vs Fine-tuned FLAN-T5 Models ✨</h3>", unsafe_allow_html=True)
276
+ st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.")
277
+
278
+ # ---- Example Conversations ----
279
+ example_conversations = {
280
+ "Select an example...": "",
281
+ "Business Meeting": """Alex: Are we ready for the client presentation tomorrow?
282
+ Sarah: Almost. I just need to finalize the quarterly figures.
283
+ Mike: The slides are done, but we should rehearse the demo.
284
+ Alex: Let's meet at 3 PM today for a dry run.
285
+ Sarah: I'll bring the updated reports.
286
+ Mike: Perfect, I'll set up the conference room.""",
287
+
288
+ "Casual Chat": """Tom: Hey, are you watching the game tonight?
289
+ Lisa: Which one? The championship?
290
+ Tom: Yeah, it starts at 8. Want to come over?
291
+ Lisa: Sure! Should I bring anything?
292
+ Tom: Just yourself! Maybe some snacks.
293
+ Lisa: Awesome, see you at 7:30!""",
294
+
295
+ "Customer Support": """Agent: Thank you for calling support. How can I help?
296
+ Customer: I can't login to my account.
297
+ Agent: Are you getting an error message?
298
+ Customer: It says 'invalid password' but I'm sure it's correct.
299
+ Agent: Let me reset your password. Check your email for a link.
300
+ Customer: Got it! Thanks for your help."""
301
+ }
302
+
303
+ # ---- Text Input ----
304
+ selected_example = st.selectbox("Choose an example conversation:", list(example_conversations.keys()))
305
+ input_text = st.text_area(
306
+ "💬 Conversation Input:",
307
+ height=250,
308
+ value=example_conversations[selected_example],
309
+ placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...",
310
+ )
311
+
312
+ # ---- Sidebar ----
313
+ st.sidebar.header("⚙️ Summary Settings")
314
+ max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10)
315
+ min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5)
316
+ num_beams = st.sidebar.slider("Number of beams", 1, 8, 4, help="Higher values = better quality but slower")
317
+
318
+ with st.sidebar.expander("Advanced Settings"):
319
+ repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.2, 0.1)
320
+ length_penalty = st.slider("Length penalty", 0.5, 2.0, 1.0, 0.1)
321
+
322
+ # ---- Generate Button ----
323
+ if st.button("✨ Generate Summaries", use_container_width=True):
324
+ if input_text.strip():
325
+ with st.spinner("🧠 Models are thinking..."):
326
+ try:
327
+ base_summary = summarizer(
328
+ input_text,
329
+ max_length=max_length,
330
+ min_length=min_length,
331
+ num_beams=num_beams,
332
+ early_stopping=True,
333
+ repetition_penalty=repetition_penalty,
334
+ length_penalty=length_penalty,
335
+ )[0]["summary_text"]
336
+
337
+ ft_summary = summarizer_ft(
338
+ input_text,
339
+ max_length=max_length,
340
+ min_length=min_length,
341
+ num_beams=num_beams,
342
+ early_stopping=True,
343
+ repetition_penalty=repetition_penalty,
344
+ length_penalty=length_penalty,
345
+ )[0]["summary_text"]
346
+
347
+ ft_summary2 = summarizer_ft2(
348
+ input_text,
349
+ max_length=max_length,
350
+ min_length=min_length,
351
+ num_beams=num_beams,
352
+ early_stopping=True,
353
+ repetition_penalty=repetition_penalty,
354
+ length_penalty=length_penalty,
355
+ )[0]["summary_text"]
356
+
357
+ st.success("✅ Summaries Generated!")
358
+
359
+ # ---- Display Results ----
360
+ st.markdown("<hr>", unsafe_allow_html=True)
361
+
362
+ # Stats row
363
+ col1, col2, col3, col4 = st.columns(4)
364
+ with col1:
365
+ st.markdown(f'<div class="stats-card"><b>Original Length</b><br>{len(input_text.split())} words</div>', unsafe_allow_html=True)
366
+ with col2:
367
+ st.markdown(f'<div class="stats-card"><b>Base Summary</b><br>{len(base_summary.split())} words</div>', unsafe_allow_html=True)
368
+ with col3:
369
+ st.markdown(f'<div class="stats-card"><b>Your Model</b><br>{len(ft_summary.split())} words</div>', unsafe_allow_html=True)
370
+ with col4:
371
+ st.markdown(f'<div class="stats-card"><b>Reference Model</b><br>{len(ft_summary2.split())} words</div>', unsafe_allow_html=True)
372
+
373
+ # Summary cards
374
+ st.markdown("<br>", unsafe_allow_html=True)
375
+ col1, col2, col3 = st.columns(3)
376
+
377
+ with col1:
378
+ st.markdown(f'''
379
+ <div class="summary-card">
380
+ <h3>🧠 Base Model</h3>
381
+ <p style="color: #a8d8ea">{base_summary}</p>
382
+ </div>
383
+ ''', unsafe_allow_html=True)
384
+
385
+ with col2:
386
+ st.markdown(f'''
387
+ <div class="summary-card">
388
+ <h3>🚀 Your Fine-tuned</h3>
389
+ <p style="color: #a8e6cf">{ft_summary}</p>
390
+ </div>
391
+ ''', unsafe_allow_html=True)
392
+
393
+ with col3:
394
+ st.markdown(f'''
395
+ <div class="summary-card">
396
+ <h3>🔬 Reference Model</h3>
397
+ <p style="color: #ffd3b6">{ft_summary2}</p>
398
+ </div>
399
+ ''', unsafe_allow_html=True)
400
+
401
+ st.markdown("<hr>", unsafe_allow_html=True)
402
+
403
+ except Exception as e:
404
+ st.error(f"❌ Error generating summaries: {str(e)}")
405
+ else:
406
+ st.warning("⚠️ Please enter a conversation to summarize.")
407
+
408
+ # ---- Footer ----
409
+ st.markdown("---")
410
+ st.markdown(
411
+ "<div style='text-align: center; color: #888;'>"
412
+ "Built with ❤️ using Streamlit & Hugging Face Transformers"
413
+ "</div>",
414
+ unsafe_allow_html=True
415
+ )
requirements.txt ADDED
Binary file (112 Bytes). View file