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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415

# import streamlit as st
# from transformers import pipeline

# # ---- Load both models ----
# @st.cache_resource
# def load_summarizers():
#     model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt"  # your fine-tuned
#     summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft)

#     model_name_ft2 = "philschmid/flan-t5-base-samsum"  # comparison fine-tuned
#     summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2)

#     model_name = "google/flan-t5-base"  # pretrained
#     summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)

#     return summarizer_ft, summarizer_ft2, summarizer


# summarizer_ft, summarizer_ft2, summarizer = load_summarizers()

# # ---- Streamlit Page Config ----
# st.set_page_config(page_title="Conversation Summarizer", page_icon="πŸ€–", layout="wide")

# # ---- Custom CSS for Styling ----
# st.markdown("""
# <style>
# /* Background gradient */
# .stApp {
#     background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364);
#     color: #f5f6f7;
#     font-family: 'Segoe UI', sans-serif;
# }

# /* Title */
# h1, h2, h3 {
#     text-align: center;
#     color: #fdfdfd;
# }

# /* Subheader accent */
# h2, h3 {
#     color: #e0e0e0;
# }

# /* Input box styling */
# textarea {
#     border-radius: 12px !important;
# }

# /* Summary cards */
# .summary-card {
#     background: rgba(255, 255, 255, 0.08);
#     border-radius: 15px;
#     padding: 20px;
#     box-shadow: 0 0 10px rgba(255,255,255,0.05);
#     transition: transform 0.2s ease-in-out;
# }
# .summary-card:hover {
#     transform: scale(1.02);
# }

# /* Section divider */
# hr {
#     border: none;
#     height: 2px;
#     background: linear-gradient(to right, #00c6ff, #0072ff);
#     margin: 30px 0;
# }

# /* Sidebar */
# [data-testid="stSidebar"] {
#     background-color: rgba(15, 25, 35, 0.95);
   
# }
# [data-testid="stSidebar"] * {
#     color: white !important;
# }

# .stButton>button {
#     background: linear-gradient(90deg, #00c6ff, #0072ff);
#     color: white;
#     border-radius: 8px;
#     font-weight: bold;
#     border: none;
#     transition: 0.3s;
# }
# .stButton>button:hover {
#     background: linear-gradient(90deg, #0072ff, #00c6ff);
#     transform: translateY(-1px);
# }

# </style>
# """, unsafe_allow_html=True)


# # ---- Header Section ----
# st.markdown("<h1>πŸ€– Conversation Summarizer</h1>", unsafe_allow_html=True)
# st.markdown("<h3>✨ Compare Pretrained vs Fine-tuned FLAN-T5 Models ✨</h3>", unsafe_allow_html=True)
# st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.")

# # ---- Text Input ----
# input_text = st.text_area(
#     "πŸ’¬ Conversation Input:",
#     height=250,
#     placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...",
# )

# # ---- Sidebar ----
# st.sidebar.header("βš™οΈ Summary Settings")
# max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10)
# min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5)
# num_beams = st.sidebar.slider("Number of beams", 1, 8, 4)

# # ---- Generate Button ----
# if st.button("✨ Generate Summaries"):
#     if input_text.strip():
#         with st.spinner("🧠 Models are thinking..."):
#             base_summary = summarizer(
#                 input_text,
#                 max_length=max_length,
#                 min_length=min_length,
#                 num_beams=num_beams,
#                 early_stopping=True,
#             )[0]["summary_text"]

#             ft_summary = summarizer_ft(
#                 input_text,
#                 max_length=max_length,
#                 min_length=min_length,
#                 num_beams=num_beams,
#                 early_stopping=True,
#             )[0]["summary_text"]

#             ft_summary2 = summarizer_ft2(
#                 input_text,
#                 max_length=max_length,
#                 min_length=min_length,
#                 num_beams=num_beams,
#                 early_stopping=True,
#             )[0]["summary_text"]

#         st.success("βœ… Summaries Generated!")

#         # ---- Display Results ----
#         st.markdown("<hr>", unsafe_allow_html=True)
#         col1, col2, col3 = st.columns(3)

#         with col1:
#             st.markdown('<div class="summary-card"><h3>🧠 Base Model</h3><p>{}</p></div>'.format(base_summary), unsafe_allow_html=True)
#         with col2:
#             st.markdown('<div class="summary-card"><h3>πŸš€ Fine-tuned (Yours)</h3><p>{}</p></div>'.format(ft_summary), unsafe_allow_html=True)
#         with col3:
#             st.markdown('<div class="summary-card"><h3>πŸ”¬ Fine-tuned (Reference)</h3><p>{}</p></div>'.format(ft_summary2), unsafe_allow_html=True)

#         st.markdown("<hr>", unsafe_allow_html=True)
#     else:
#         st.warning("⚠️ Please enter a conversation to summarize.")

import streamlit as st
from transformers import pipeline

# ---- Load both models ----
@st.cache_resource
def load_summarizers():
    model_name_ft = "AIsumit123/flan-t5-base_samsum_best_ckpt"  # your fine-tuned
    summarizer_ft = pipeline("summarization", model=model_name_ft, tokenizer=model_name_ft)

    model_name_ft2 = "philschmid/flan-t5-base-samsum"  # comparison fine-tuned
    summarizer_ft2 = pipeline("summarization", model=model_name_ft2, tokenizer=model_name_ft2)

    model_name = "google/flan-t5-base"  # pretrained
    summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)

    return summarizer_ft, summarizer_ft2, summarizer


summarizer_ft, summarizer_ft2, summarizer = load_summarizers()

# ---- Streamlit Page Config ----
st.set_page_config(page_title="Conversation Summarizer", page_icon="πŸ€–", layout="wide")

# ---- Custom CSS for Styling ----
st.markdown("""

<style>

/* Background gradient */

.stApp {

    background: linear-gradient(to bottom right, #0f2027, #203a43, #2c5364);

    color: #f5f6f7;

    font-family: 'Segoe UI', sans-serif;

}



/* Title */

h1, h2, h3 {

    text-align: center;

    color: #fdfdfd;

}



/* Subheader accent */

h2, h3 {

    color: #e0e0e0;

}



/* Input box styling */

textarea {

    border-radius: 12px !important;

}



/* Summary cards */

.summary-card {

    background: rgba(255, 255, 255, 0.08);

    border-radius: 15px;

    padding: 20px;

    box-shadow: 0 0 10px rgba(255,255,255,0.05);

    transition: transform 0.2s ease-in-out;

    height: 100%;

}

.summary-card:hover {

    transform: scale(1.02);

}



/* Section divider */

hr {

    border: none;

    height: 2px;

    background: linear-gradient(to right, #00c6ff, #0072ff);

    margin: 30px 0;

}



/* Sidebar Styling - FIXED TEXT COLOR */

[data-testid="stSidebar"] {

    background-color: rgba(15, 25, 35, 0.95);

}



[data-testid="stSidebar"] * {

    color: white !important;

}



[data-testid="stSidebar"] .stSlider label,

[data-testid="stSidebar"] .stSlider div,

[data-testid="stSidebar"] .stSlider span {

    color: white !important;

}



/* Button styling */

.stButton>button {

    background: linear-gradient(90deg, #00c6ff, #0072ff);

    color: white;

    border-radius: 8px;

    font-weight: bold;

    border: none;

    transition: 0.3s;

    width: 100%;

    padding: 12px;

}

.stButton>button:hover {

    background: linear-gradient(90deg, #0072ff, #00c6ff);

    transform: translateY(-1px);

    box-shadow: 0 4px 12px rgba(0, 114, 255, 0.3);

}



/* Stats cards */

.stats-card {

    background: rgba(255, 255, 255, 0.05);

    border-radius: 10px;

    padding: 15px;

    text-align: center;

    margin: 5px;

}

</style>

""", unsafe_allow_html=True)

# ---- Header Section ----
st.markdown("<h1>πŸ€– Conversation Summarizer</h1>", unsafe_allow_html=True)
st.markdown("<h3>✨ Compare Pretrained vs Fine-tuned FLAN-T5 Models ✨</h3>", unsafe_allow_html=True)
st.write("Paste your **conversation** below and instantly compare how fine-tuning changes summary quality.")

# ---- Example Conversations ----
example_conversations = {
    "Select an example...": "",
    "Business Meeting": """Alex: Are we ready for the client presentation tomorrow?

Sarah: Almost. I just need to finalize the quarterly figures.

Mike: The slides are done, but we should rehearse the demo.

Alex: Let's meet at 3 PM today for a dry run.

Sarah: I'll bring the updated reports.

Mike: Perfect, I'll set up the conference room.""",
    
    "Casual Chat": """Tom: Hey, are you watching the game tonight?

Lisa: Which one? The championship?

Tom: Yeah, it starts at 8. Want to come over?

Lisa: Sure! Should I bring anything?

Tom: Just yourself! Maybe some snacks.

Lisa: Awesome, see you at 7:30!""",
    
    "Customer Support": """Agent: Thank you for calling support. How can I help?

Customer: I can't login to my account.

Agent: Are you getting an error message?

Customer: It says 'invalid password' but I'm sure it's correct.

Agent: Let me reset your password. Check your email for a link.

Customer: Got it! Thanks for your help."""
}

# ---- Text Input ----
selected_example = st.selectbox("Choose an example conversation:", list(example_conversations.keys()))
input_text = st.text_area(
    "πŸ’¬ Conversation Input:",
    height=250,
    value=example_conversations[selected_example],
    placeholder="Person A: Hi, how are you?\nPerson B: I'm good, just finished work...",
)

# ---- Sidebar ----
st.sidebar.header("βš™οΈ Summary Settings")
max_length = st.sidebar.slider("Max summary length", 30, 200, 100, step=10)
min_length = st.sidebar.slider("Min summary length", 10, 100, 30, step=5)
num_beams = st.sidebar.slider("Number of beams", 1, 8, 4, help="Higher values = better quality but slower")

with st.sidebar.expander("Advanced Settings"):
    repetition_penalty = st.slider("Repetition penalty", 1.0, 2.0, 1.2, 0.1)
    length_penalty = st.slider("Length penalty", 0.5, 2.0, 1.0, 0.1)

# ---- Generate Button ----
if st.button("✨ Generate Summaries", use_container_width=True):
    if input_text.strip():
        with st.spinner("🧠 Models are thinking..."):
            try:
                base_summary = summarizer(
                    input_text,
                    max_length=max_length,
                    min_length=min_length,
                    num_beams=num_beams,
                    early_stopping=True,
                    repetition_penalty=repetition_penalty,
                    length_penalty=length_penalty,
                )[0]["summary_text"]

                ft_summary = summarizer_ft(
                    input_text,
                    max_length=max_length,
                    min_length=min_length,
                    num_beams=num_beams,
                    early_stopping=True,
                    repetition_penalty=repetition_penalty,
                    length_penalty=length_penalty,
                )[0]["summary_text"]

                ft_summary2 = summarizer_ft2(
                    input_text,
                    max_length=max_length,
                    min_length=min_length,
                    num_beams=num_beams,
                    early_stopping=True,
                    repetition_penalty=repetition_penalty,
                    length_penalty=length_penalty,
                )[0]["summary_text"]

                st.success("βœ… Summaries Generated!")

                # ---- Display Results ----
                st.markdown("<hr>", unsafe_allow_html=True)
                
                # Stats row
                col1, col2, col3, col4 = st.columns(4)
                with col1:
                    st.markdown(f'<div class="stats-card"><b>Original Length</b><br>{len(input_text.split())} words</div>', unsafe_allow_html=True)
                with col2:
                    st.markdown(f'<div class="stats-card"><b>Base Summary</b><br>{len(base_summary.split())} words</div>', unsafe_allow_html=True)
                with col3:
                    st.markdown(f'<div class="stats-card"><b>Your Model</b><br>{len(ft_summary.split())} words</div>', unsafe_allow_html=True)
                with col4:
                    st.markdown(f'<div class="stats-card"><b>Reference Model</b><br>{len(ft_summary2.split())} words</div>', unsafe_allow_html=True)

                # Summary cards
                st.markdown("<br>", unsafe_allow_html=True)
                col1, col2, col3 = st.columns(3)

                with col1:
                    st.markdown(f'''

                    <div class="summary-card">

                        <h3>🧠 Base Model</h3>

                        <p style="color: #a8d8ea">{base_summary}</p>

                    </div>

                    ''', unsafe_allow_html=True)
                    
                with col2:
                    st.markdown(f'''

                    <div class="summary-card">

                        <h3>πŸš€ Your Fine-tuned</h3>

                        <p style="color: #a8e6cf">{ft_summary}</p>

                    </div>

                    ''', unsafe_allow_html=True)
                    
                with col3:
                    st.markdown(f'''

                    <div class="summary-card">

                        <h3>πŸ”¬ Reference Model</h3>

                        <p style="color: #ffd3b6">{ft_summary2}</p>

                    </div>

                    ''', unsafe_allow_html=True)

                st.markdown("<hr>", unsafe_allow_html=True)
                
            except Exception as e:
                st.error(f"❌ Error generating summaries: {str(e)}")
    else:
        st.warning("⚠️ Please enter a conversation to summarize.")

# ---- Footer ----
st.markdown("---")
st.markdown(
    "<div style='text-align: center; color: #888;'>"
    "Built with ❀️ using Streamlit & Hugging Face Transformers"
    "</div>", 
    unsafe_allow_html=True
)