Menixis commited on
Commit
ac3b103
·
verified ·
1 Parent(s): edc1a82

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +380 -423
streamlit_app.py CHANGED
@@ -1,14 +1,11 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
- ระบบสร้างเอกสารอัตโนมัติ - Premium UI v3
4
- =========================================
5
- Visually rich Streamlit app with:
6
- - Gradient mesh background + floating blobs
7
- - Glassmorphism cards
8
- - Animated step indicator with progress bar
9
- - Custom Google Fonts (Inter + Sarabun)
10
- - Micro-interactions & hover effects
11
- - Decorative geometric elements
12
  """
13
 
14
  import os
@@ -95,134 +92,88 @@ def lookup_po_in_bytes(po_number, file_bytes, sheet_name=None, po_column="poNo")
95
  # =============================================================================
96
  st.set_page_config(
97
  page_title="Auto Form Generator",
98
- page_icon="📄",
99
  layout="wide",
100
- initial_sidebar_state="expanded",
101
  )
102
 
103
 
104
  # =============================================================================
105
- # Premium CSS — Rich visual design
106
  # =============================================================================
107
  st.markdown("""
108
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Sarabun:wght@400;500;600;700&display=swap" rel="stylesheet">
109
 
110
  <style>
111
- /* ─────────────── GLOBAL FOUNDATION ─────────────── */
 
 
 
 
 
 
 
 
 
 
112
 
113
- /* Hide Streamlit chrome but keep sidebar toggle */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  [data-testid="stToolbar"] { visibility: hidden; height: 0; position: fixed; }
115
  [data-testid="stDecoration"] { display: none; }
116
  footer { visibility: hidden; }
117
  #MainMenu { visibility: hidden; }
118
-
119
- /* Make top header BAR transparent + zero-height */
120
  [data-testid="stHeader"] {
121
  background: transparent !important;
122
  height: 0 !important;
123
  min-height: 0 !important;
124
  padding: 0 !important;
125
  }
126
- [data-testid="stHeader"] > div {
127
- background: transparent !important;
128
- }
129
 
130
- /* HIDE ALL sidebar toggle buttons (the 3-dot icon and close X) */
 
 
 
 
 
 
131
  [data-testid="collapsedControl"],
132
  [data-testid="stSidebarCollapsedControl"],
133
- [data-testid="stSidebarHeader"] button,
134
- [data-testid="stSidebar"] [kind="header"],
135
- [data-testid="stSidebar"] button[kind="headerNoPadding"],
136
  button[kind="headerNoPadding"] {
137
  display: none !important;
138
- visibility: hidden !important;
139
- width: 0 !important;
140
- height: 0 !important;
141
- }
142
-
143
- /* FORCE sidebar to always be visible (no collapse) */
144
- section[data-testid="stSidebar"] {
145
- min-width: 18rem !important;
146
- width: 18rem !important;
147
- max-width: 18rem !important;
148
- transform: translateX(0) !important;
149
- visibility: visible !important;
150
- margin-left: 0 !important;
151
- }
152
- section[data-testid="stSidebar"][aria-expanded="false"] {
153
- margin-left: 0 !important;
154
- transform: translateX(0) !important;
155
- visibility: visible !important;
156
- }
157
-
158
- /* Apply premium fonts */
159
- html, body, [class*="css"], .stApp {
160
- font-family: 'Inter', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif !important;
161
  }
162
 
163
- /* Page background — AURORA (purple / pink / cyan flowing mesh) */
164
- .stApp {
165
- background:
166
- radial-gradient(at 20% 0%, rgba(168, 85, 247, 0.28) 0px, transparent 50%),
167
- radial-gradient(at 80% 15%, rgba(236, 72, 153, 0.22) 0px, transparent 50%),
168
- radial-gradient(at 90% 85%, rgba(59, 130, 246, 0.25) 0px, transparent 50%),
169
- radial-gradient(at 10% 95%, rgba(34, 211, 238, 0.20) 0px, transparent 50%),
170
- linear-gradient(180deg, #F5F3FF 0%, #EFF6FF 50%, #F0FDFA 100%) !important;
171
- background-attachment: fixed;
172
- }
173
-
174
- /* ─── ALTERNATIVE BACKGROUNDS ─────────────────────────────────────
175
- เปลี่ยน background ด้านบนเป็น 1 ใน 4 ทางเลือกนี้ได้ (uncomment 1 ชุด):
176
-
177
- OPTION 2 — OCEAN (blue/teal calm):
178
- background:
179
- radial-gradient(at 30% 10%, rgba(56, 189, 248, 0.25) 0px, transparent 50%),
180
- radial-gradient(at 75% 50%, rgba(14, 165, 233, 0.20) 0px, transparent 50%),
181
- radial-gradient(at 20% 90%, rgba(20, 184, 166, 0.22) 0px, transparent 50%),
182
- linear-gradient(180deg, #ECFEFF 0%, #F0F9FF 100%) !important;
183
-
184
- OPTION 3 — SUNSET (warm pink/orange friendly):
185
- background:
186
- radial-gradient(at 25% 15%, rgba(251, 113, 133, 0.25) 0px, transparent 50%),
187
- radial-gradient(at 80% 30%, rgba(251, 146, 60, 0.20) 0px, transparent 50%),
188
- radial-gradient(at 60% 85%, rgba(244, 114, 182, 0.22) 0px, transparent 50%),
189
- linear-gradient(180deg, #FFF7ED 0%, #FFF1F2 100%) !important;
190
-
191
- OPTION 4 — MIDNIGHT (premium dark — also need to flip text colors):
192
- background:
193
- radial-gradient(at 20% 0%, rgba(99, 102, 241, 0.35) 0px, transparent 50%),
194
- radial-gradient(at 85% 25%, rgba(168, 85, 247, 0.25) 0px, transparent 50%),
195
- radial-gradient(at 75% 90%, rgba(59, 130, 246, 0.30) 0px, transparent 50%),
196
- linear-gradient(180deg, #0F172A 0%, #1E293B 100%) !important;
197
-
198
- OPTION 5 — FOREST (green/emerald natural):
199
- background:
200
- radial-gradient(at 20% 10%, rgba(34, 197, 94, 0.20) 0px, transparent 50%),
201
- radial-gradient(at 80% 40%, rgba(20, 184, 166, 0.22) 0px, transparent 50%),
202
- radial-gradient(at 50% 90%, rgba(132, 204, 22, 0.18) 0px, transparent 50%),
203
- linear-gradient(180deg, #F0FDF4 0%, #ECFDF5 100%) !important;
204
- ──────────────────────────────────────────────────────────────── */
205
-
206
- /* Main content container */
207
  .block-container {
208
  padding-top: 1.5rem !important;
209
  padding-bottom: 4rem !important;
210
  max-width: 1200px !important;
211
  }
212
 
213
- /* ─────────────── ENTRANCE ANIMATIONS ─────────────── */
214
-
215
  @keyframes fadeInUp {
216
  from { opacity: 0; transform: translateY(20px); }
217
  to { opacity: 1; transform: translateY(0); }
218
  }
219
  @keyframes pulse {
220
- 0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
221
- 50% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
222
- }
223
- @keyframes shimmer {
224
- 0% { background-position: -1000px 0; }
225
- 100% { background-position: 1000px 0; }
226
  }
227
  @keyframes blob {
228
  0%, 100% { transform: translate(0, 0) scale(1); }
@@ -230,67 +181,59 @@ st.markdown("""
230
  66% { transform: translate(-20px, 20px) scale(0.9); }
231
  }
232
 
233
- /* ─────────────── HERO SECTION ─────────────── */
234
-
235
  .hero {
236
  position: relative;
237
- background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 35%, #2563EB 70%, #0EA5E9 100%);
238
- padding: 3rem 2.5rem;
239
  border-radius: 24px;
240
- color: white;
241
  margin-bottom: 2rem;
242
  overflow: hidden;
243
  box-shadow:
244
- 0 20px 50px -15px rgba(79, 70, 229, 0.4),
245
- 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
246
  animation: fadeInUp 0.6s ease;
247
  }
248
-
249
- /* Floating decorative blobs in hero */
250
  .hero::before {
251
  content: "";
252
  position: absolute;
253
  top: -120px;
254
  right: -80px;
255
- width: 350px;
256
- height: 350px;
257
- background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 60%);
258
  border-radius: 50%;
259
- animation: blob 12s ease-in-out infinite;
260
  }
261
  .hero::after {
262
  content: "";
263
  position: absolute;
264
  bottom: -100px;
265
  left: 30%;
266
- width: 280px;
267
- height: 280px;
268
- background: radial-gradient(circle, rgba(236, 72, 153, 0.2) 0%, transparent 60%);
269
  border-radius: 50%;
270
- animation: blob 15s ease-in-out infinite reverse;
271
  }
272
-
273
- /* Decorative dot pattern overlay */
274
  .hero-pattern {
275
  position: absolute;
276
  inset: 0;
277
- background-image: radial-gradient(circle, rgba(255,255,255,0.1) 1px, transparent 1px);
278
  background-size: 24px 24px;
279
- opacity: 0.5;
280
  pointer-events: none;
281
  }
282
-
283
- .hero-content {
284
- position: relative;
285
- z-index: 2;
286
- }
287
  .hero-badge {
288
  display: inline-flex;
289
  align-items: center;
290
  gap: 0.4rem;
291
- background: rgba(255, 255, 255, 0.15);
292
  backdrop-filter: blur(10px);
293
- border: 1px solid rgba(255, 255, 255, 0.2);
 
294
  padding: 0.4rem 0.9rem;
295
  border-radius: 999px;
296
  font-size: 0.78rem;
@@ -300,7 +243,7 @@ st.markdown("""
300
  text-transform: uppercase;
301
  }
302
  .hero h1 {
303
- color: white !important;
304
  font-size: 2.75rem !important;
305
  font-weight: 800 !important;
306
  margin: 0 0 0.75rem 0 !important;
@@ -308,173 +251,135 @@ st.markdown("""
308
  line-height: 1.1 !important;
309
  }
310
  .hero-subtitle {
311
- color: rgba(255,255,255,0.85) !important;
312
  font-size: 1.05rem !important;
313
  font-weight: 400 !important;
314
- max-width: 580px;
315
  line-height: 1.5;
316
  }
317
-
318
- /* Hero stats row */
319
  .hero-stats {
320
- display: flex;
321
- gap: 2rem;
322
- margin-top: 1.75rem;
323
- flex-wrap: wrap;
324
- }
325
- .hero-stat {
326
- display: flex;
327
- flex-direction: column;
328
  }
329
  .hero-stat-value {
330
- font-size: 1.5rem;
331
- font-weight: 700;
332
- color: white;
333
- line-height: 1;
334
  }
335
  .hero-stat-label {
336
  font-size: 0.75rem;
337
- color: rgba(255,255,255,0.75);
338
  text-transform: uppercase;
339
  letter-spacing: 0.06em;
340
  margin-top: 0.25rem;
341
  }
342
 
343
- /* ─────────────── STEP INDICATOR ─────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
344
 
 
345
  .steps-wrapper {
346
- background: rgba(255, 255, 255, 0.7);
347
  backdrop-filter: blur(20px);
348
- -webkit-backdrop-filter: blur(20px);
349
- border: 1px solid rgba(255, 255, 255, 0.8);
350
  border-radius: 16px;
351
  padding: 1.25rem 1.5rem;
352
  margin-bottom: 2rem;
353
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
354
  animation: fadeInUp 0.6s ease 0.1s both;
355
  }
356
- .steps-row {
357
- display: flex;
358
- align-items: center;
359
- gap: 0;
360
- position: relative;
361
- }
362
- .step {
363
- display: flex;
364
- align-items: center;
365
- gap: 0.7rem;
366
- flex: 0 0 auto;
367
- }
368
  .step-circle {
369
- width: 40px;
370
- height: 40px;
371
- border-radius: 50%;
372
- display: flex;
373
- align-items: center;
374
- justify-content: center;
375
- font-weight: 700;
376
- font-size: 1rem;
377
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
378
- position: relative;
379
- z-index: 2;
380
  }
381
  .step-default .step-circle {
382
- background: #F1F5F9;
383
- color: #94A3B8;
384
- border: 2px solid #E2E8F0;
385
  }
386
  .step-active .step-circle {
387
- background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
388
  color: white;
389
- box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
390
  animation: pulse 2s infinite;
391
  }
392
  .step-done .step-circle {
393
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
394
  color: white;
395
- box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
396
  }
397
- .step-label {
398
- font-size: 0.85rem;
399
- font-weight: 500;
400
- color: #64748B;
401
- white-space: nowrap;
402
- }
403
- .step-active .step-label { color: #4F46E5; font-weight: 600; }
404
- .step-done .step-label { color: #059669; font-weight: 600; }
405
 
406
- /* Progress bar between steps */
407
  .step-bar {
408
- flex: 1;
409
- height: 3px;
410
- background: #E2E8F0;
411
- margin: 0 1rem;
412
- border-radius: 999px;
413
- overflow: hidden;
414
- position: relative;
415
  }
416
  .step-bar-fill {
417
- position: absolute;
418
- inset: 0;
419
  background: linear-gradient(90deg, #10B981 0%, #059669 100%);
420
  transform-origin: left;
421
  transition: transform 0.5s ease;
422
  }
423
- .step-bar-fill.empty { transform: scaleX(0); }
424
- .step-bar-fill.full { transform: scaleX(1); }
425
-
426
- /* ─────────────── CARDS ─────────────── */
427
-
428
- .glass-card {
429
- background: rgba(255, 255, 255, 0.85);
430
- backdrop-filter: blur(20px);
431
- -webkit-backdrop-filter: blur(20px);
432
- border: 1px solid rgba(255, 255, 255, 0.9);
433
- border-radius: 20px;
434
- padding: 1.75rem;
435
- box-shadow:
436
- 0 1px 3px rgba(0, 0, 0, 0.04),
437
- 0 8px 24px rgba(0, 0, 0, 0.04);
438
- transition: all 0.3s ease;
439
- animation: fadeInUp 0.6s ease 0.2s both;
440
- }
441
 
 
442
  .card-header {
443
- display: flex;
444
- align-items: center;
445
- gap: 0.75rem;
446
  margin-bottom: 1.25rem;
447
  }
448
  .card-icon {
449
- width: 40px;
450
- height: 40px;
451
  border-radius: 12px;
452
- display: flex;
453
- align-items: center;
454
- justify-content: center;
455
  font-size: 1.25rem;
456
  }
457
- .card-icon-1 { background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 100%); }
458
- .card-icon-2 { background: linear-gradient(135deg, #F3E8FF 0%, #E9D5FF 100%); }
459
  .card-title {
460
- font-size: 1.1rem;
461
- font-weight: 700;
462
- color: #0F172A;
463
- margin: 0;
464
- line-height: 1.2;
465
  }
466
  .card-subtitle {
467
- font-size: 0.8rem;
468
- color: #64748B;
469
- margin: 0.15rem 0 0 0;
470
- font-weight: 500;
471
  }
472
 
473
- /* ─────────────── VENDOR PREVIEW CARDS ─────────────── */
474
-
475
  .vendor-card {
476
- background: linear-gradient(135deg, #EEF2FF 0%, #F0F9FF 100%);
477
- border: 1px solid #C7D2FE;
478
  padding: 1rem 1.25rem;
479
  border-radius: 14px;
480
  margin: 0.6rem 0;
@@ -484,85 +389,72 @@ st.markdown("""
484
  }
485
  .vendor-card:hover {
486
  transform: translateX(2px);
487
- box-shadow: 0 4px 12px rgba(79, 70, 229, 0.1);
488
  }
489
  .vendor-card::before {
490
  content: "";
491
  position: absolute;
492
- left: 0;
493
- top: 0;
494
- bottom: 0;
495
  width: 4px;
496
- background: linear-gradient(180deg, #4F46E5 0%, #7C3AED 100%);
497
  }
498
  .vendor-card-label {
499
  font-size: 0.7rem;
500
  text-transform: uppercase;
501
- color: #4F46E5;
502
  font-weight: 700;
503
  letter-spacing: 0.06em;
504
  margin-bottom: 0.4rem;
505
- display: flex;
506
- align-items: center;
507
- gap: 0.4rem;
508
  }
509
  .vendor-card-value {
510
  font-size: 1.05rem;
511
- color: #0F172A;
512
  font-weight: 600;
513
  line-height: 1.4;
514
  }
515
 
516
- /* ─────────────── BUTTONS ─────────────── */
517
-
518
- /* Primary button — Generate */
519
  .stButton button[kind="primary"] {
520
- background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #2563EB 100%) !important;
521
  background-size: 200% 200% !important;
522
  border: none !important;
 
523
  box-shadow:
524
- 0 4px 14px rgba(79, 70, 229, 0.35),
525
- 0 0 0 1px rgba(255,255,255,0.1) inset !important;
526
  font-weight: 700 !important;
527
  height: 3.25rem !important;
528
  font-size: 1.05rem !important;
529
- letter-spacing: 0.01em !important;
530
  transition: all 0.3s ease !important;
531
  border-radius: 12px !important;
532
  }
533
  .stButton button[kind="primary"]:hover {
534
  transform: translateY(-2px);
535
  box-shadow:
536
- 0 8px 24px rgba(79, 70, 229, 0.45),
537
- 0 0 0 1px rgba(255,255,255,0.2) inset !important;
538
  background-position: 100% 100% !important;
539
  }
540
- .stButton button[kind="primary"]:active {
541
- transform: translateY(0);
542
- }
543
-
544
- /* Secondary button — Fetch */
545
  .stButton button[kind="secondary"] {
546
- background: white !important;
547
- border: 1.5px solid #C7D2FE !important;
548
- color: #4F46E5 !important;
549
  font-weight: 600 !important;
550
  height: 3rem !important;
551
  border-radius: 12px !important;
552
  transition: all 0.2s ease !important;
553
  }
554
  .stButton button[kind="secondary"]:hover {
555
- background: #EEF2FF !important;
556
- border-color: #4F46E5 !important;
557
  transform: translateY(-1px);
558
  }
559
-
560
- /* Download button — Emerald accent */
561
  .stDownloadButton button {
562
  background: linear-gradient(135deg, #10B981 0%, #059669 100%) !important;
563
  color: white !important;
564
  border: none !important;
565
- box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35) !important;
566
  font-weight: 700 !important;
567
  height: 3.25rem !important;
568
  font-size: 1.05rem !important;
@@ -571,23 +463,59 @@ st.markdown("""
571
  }
572
  .stDownloadButton button:hover {
573
  transform: translateY(-2px);
574
- box-shadow: 0 8px 24px rgba(16, 185, 129, 0.45) !important;
575
  }
576
 
577
- /* ─────────────── INPUTS ─────────────── */
578
-
579
  .stTextInput input,
580
- .stSelectbox > div > div,
581
  .stTextArea textarea {
 
 
 
582
  border-radius: 12px !important;
583
- border: 1.5px solid #E2E8F0 !important;
584
- transition: all 0.2s ease !important;
585
  font-size: 0.95rem !important;
586
  }
 
 
 
 
587
  .stTextInput input:focus,
588
  .stTextArea textarea:focus {
589
- border-color: #4F46E5 !important;
590
- box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
  }
592
 
593
  /* Labels */
@@ -596,76 +524,114 @@ st.markdown("""
596
  .stRadio label,
597
  .stFileUploader label {
598
  font-weight: 600 !important;
599
- color: #334155 !important;
600
  font-size: 0.85rem !important;
601
  }
602
 
603
- /* ─────────────── SIDEBAR ─────────────── */
604
-
605
- [data-testid="stSidebar"] {
606
- background: linear-gradient(180deg, #FFFFFF 0%, #F8FAFC 100%) !important;
607
- border-right: 1px solid #E2E8F0;
608
- }
609
- [data-testid="stSidebar"] .block-container {
610
- padding-top: 2rem !important;
611
- }
612
-
613
- /* ─────────────── ALERTS ─────────────── */
614
-
615
  .stAlert {
616
  border-radius: 14px !important;
617
  border: none !important;
618
  backdrop-filter: blur(10px);
619
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
620
 
621
- /* ─────────────── SECTION TITLE ─────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
 
 
623
  .section-title {
624
  font-size: 0.95rem;
625
  font-weight: 700;
626
- color: #0F172A;
627
  margin: 1.25rem 0 0.75rem 0;
628
- display: flex;
629
- align-items: center;
630
- gap: 0.5rem;
631
  }
632
  .section-title::before {
633
  content: "";
634
- width: 4px;
635
- height: 18px;
636
- background: linear-gradient(180deg, #4F46E5 0%, #7C3AED 100%);
637
  border-radius: 2px;
638
  }
639
 
640
- /* ─────────────── EMPTY STATE ─────────────── */
641
-
642
  .empty-state {
643
  text-align: center;
644
  padding: 2rem 1rem;
645
- background: linear-gradient(135deg, #F8FAFC 0%, #F1F5F9 100%);
646
  border-radius: 14px;
647
- border: 2px dashed #CBD5E1;
648
  margin: 1rem 0;
649
  }
650
- .empty-state-icon {
651
- font-size: 2.5rem;
652
- margin-bottom: 0.5rem;
653
- opacity: 0.5;
654
- }
655
- .empty-state-text {
656
- color: #64748B;
657
- font-size: 0.9rem;
658
- margin: 0;
659
- }
660
-
661
- /* ─────────────── DIVIDER ─────────────── */
662
 
 
663
  hr {
664
  border: none !important;
665
  height: 1px !important;
666
- background: linear-gradient(90deg, transparent 0%, #E2E8F0 50%, transparent 100%) !important;
667
  margin: 1rem 0 !important;
668
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
  </style>
670
  """, unsafe_allow_html=True)
671
 
@@ -678,91 +644,14 @@ for key, default in [
678
  ("last_po", ""),
679
  ("generated_file", None),
680
  ("generated_filename", None),
 
 
 
681
  ]:
682
  if key not in st.session_state:
683
  st.session_state[key] = default
684
 
685
 
686
- # =============================================================================
687
- # Sidebar
688
- # =============================================================================
689
- with st.sidebar:
690
- st.markdown("""
691
- <div style="padding: 0 0 1rem 0;">
692
- <div style="display: flex; align-items: center; gap: 0.6rem;">
693
- <div style="width: 36px; height: 36px; border-radius: 10px;
694
- background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
695
- display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
696
- 📊
697
- </div>
698
- <div>
699
- <div style="font-weight: 700; font-size: 1rem; color: #0F172A; line-height: 1;">แหล่งข้อมูล</div>
700
- <div style="font-size: 0.75rem; color: #64748B; margin-top: 0.2rem;">Data source</div>
701
- </div>
702
- </div>
703
- </div>
704
- """, unsafe_allow_html=True)
705
-
706
- source = st.radio(
707
- "เลือกแหล่งข้อมูล:",
708
- ["🎯 ใช้ไฟล์ตัวอย่าง", "📁 อัปโหลดไฟล์ของฉัน"],
709
- index=0,
710
- label_visibility="collapsed",
711
- )
712
-
713
- excel_bytes = None
714
- sample_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
715
- 'sample_po_data.xlsx')
716
-
717
- if source.startswith("📁"):
718
- uploaded = st.file_uploader("เลือกไฟล์ Excel (.xlsx)",
719
- type=['xlsx'],
720
- accept_multiple_files=False)
721
- if uploaded:
722
- excel_bytes = uploaded.read()
723
- st.success(f"✓ {uploaded.name}")
724
- st.caption(f"{len(excel_bytes) / 1024:.1f} KB")
725
- else:
726
- if os.path.exists(sample_path):
727
- with open(sample_path, 'rb') as f:
728
- excel_bytes = f.read()
729
- st.info("📋 กำลังใช้ไฟล์ตัวอย่าง")
730
- st.markdown("""
731
- <div style="background: #F1F5F9; padding: 0.6rem 0.85rem; border-radius: 10px;
732
- font-size: 0.78rem; margin-top: 0.5rem; line-height: 1.7;">
733
- <div style="color: #475569; font-weight: 600; margin-bottom: 0.3rem;">
734
- ตัวอย่าง PO ที่ใช้ทดสอบ:
735
- </div>
736
- <code style="background: white; padding: 2px 8px; border-radius: 6px;">4500987654</code><br>
737
- <code style="background: white; padding: 2px 8px; border-radius: 6px;">4500987655</code><br>
738
- <code style="background: white; padding: 2px 8px; border-radius: 6px;">4500987656</code>
739
- </div>
740
- """, unsafe_allow_html=True)
741
-
742
- st.markdown("<hr>", unsafe_allow_html=True)
743
-
744
- with st.expander("⚙️ ตั้งค่าขั้นสูง"):
745
- po_column = st.text_input("ชื่อคอลัมน์ PO:",
746
- value="poNo",
747
- help="ปกติ `poNo`")
748
- sheet_name = st.text_input("ชื่อ Sheet:",
749
- value="",
750
- help="เว้นว่าง = sheet แรก")
751
-
752
- st.markdown("<hr>", unsafe_allow_html=True)
753
- st.markdown(
754
- """
755
- <div style='font-size: 0.72rem; color: #94A3B8; text-align: center; padding: 1rem 0;'>
756
- <div style="margin-bottom: 0.4rem;">Made with ❤️ for ปตท.</div>
757
- <div style="font-size: 0.68rem; opacity: 0.7;">
758
- Streamlit · Hugging Face Spaces
759
- </div>
760
- </div>
761
- """,
762
- unsafe_allow_html=True,
763
- )
764
-
765
-
766
  # =============================================================================
767
  # Hero Section
768
  # =============================================================================
@@ -771,7 +660,7 @@ st.markdown("""
771
  <div class="hero-pattern"></div>
772
  <div class="hero-content">
773
  <div class="hero-badge">
774
- ⚡ Auto Document Generator
775
  </div>
776
  <h1>Auto Form Generator</h1>
777
  <p class="hero-subtitle">
@@ -798,27 +687,80 @@ st.markdown("""
798
 
799
 
800
  # =============================================================================
801
- # Step Indicator (animated, reacts to current form state)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
802
  # =============================================================================
803
  has_lookup = bool(st.session_state.lookup_data)
804
  has_file = bool(st.session_state.generated_file)
805
 
806
- # Read current widget values from session_state (widgets are rendered below
807
- # but Streamlit persists values via key=)
808
  cur_po = st.session_state.get("po_input_widget", "") or ""
809
  cur_doc = st.session_state.get("doc_number_widget", "") or ""
810
  cur_signer = st.session_state.get("signer_widget", "") or ""
811
  cur_form = st.session_state.get("form_select_widget", FORM_TYPES[0]["label"])
812
 
813
- # Did the user change anything since the last successful generate?
814
  inputs_match_snapshot = (
815
  cur_po.strip() == st.session_state.get("last_gen_po", "") and
816
  cur_doc.strip() == st.session_state.get("last_gen_doc", "") and
817
  cur_signer.strip() == st.session_state.get("last_gen_signer", "") and
818
  cur_form == st.session_state.get("last_gen_form", "")
819
  )
820
-
821
- # Step 3 is only "done" if a file exists AND nothing has been edited since
822
  has_generated = has_file and inputs_match_snapshot
823
 
824
  if has_generated:
@@ -898,14 +840,14 @@ with left_col:
898
  if not po_number.strip():
899
  st.warning("⚠ กรุณากรอกเลข PO ก่อน")
900
  elif not excel_bytes:
901
- st.error("ไม่มีไฟล์ Excel — กรุณาอัปโหลดที่ sidebar")
902
  else:
903
  with st.spinner("กำลังค้นหา..."):
904
  try:
905
  result, available_cols = lookup_po_in_bytes(
906
  po_number.strip(), excel_bytes,
907
- sheet_name=sheet_name or None,
908
- po_column=po_column.strip(),
909
  )
910
  if isinstance(result, dict) and "__error__" in result:
911
  st.error(result["__error__"])
@@ -923,7 +865,6 @@ with left_col:
923
  except Exception as e:
924
  st.error(f"❌ ผิดพลาด: {e}")
925
 
926
- # Vendor preview
927
  if st.session_state.lookup_data:
928
  st.markdown('<div class="section-title">ข้อมูลที่ดึงจาก Excel</div>',
929
  unsafe_allow_html=True)
@@ -1048,8 +989,6 @@ with right_col:
1048
 
1049
  st.session_state.generated_file = output_bytes
1050
  st.session_state.generated_filename = filename
1051
- # Snapshot inputs used for this generation — so step indicator
1052
- # can detect if the user edits anything afterwards
1053
  st.session_state.last_gen_po = po_number.strip()
1054
  st.session_state.last_gen_doc = doc_number.strip()
1055
  st.session_state.last_gen_signer = signer.strip()
@@ -1058,18 +997,17 @@ with right_col:
1058
  except Exception as e:
1059
  st.error(f"❌ ไม่สามารถสร้างเอกสารได้: {e}")
1060
 
1061
- # Download section
1062
  if st.session_state.generated_file:
1063
  st.markdown("<div style='height: 0.75rem;'></div>", unsafe_allow_html=True)
1064
  st.markdown("""
1065
- <div style="background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
1066
- border: 1px solid #6EE7B7; padding: 0.85rem 1rem; border-radius: 14px;
1067
  margin-bottom: 0.75rem;">
1068
  <div style="display: flex; align-items: center; gap: 0.5rem;">
1069
- <span style="background: #10B981; color: white; width: 24px; height: 24px;
1070
  border-radius: 50%; display: inline-flex; align-items: center;
1071
  justify-content: center; font-size: 0.85rem;">✓</span>
1072
- <span style="font-weight: 600; color: #047857;">สร้างเอกสารสำเร็จ!</span>
1073
  </div>
1074
  </div>
1075
  """, unsafe_allow_html=True)
@@ -1084,17 +1022,36 @@ with right_col:
1084
 
1085
 
1086
  # =============================================================================
1087
- # Footer
1088
  # =============================================================================
1089
  st.markdown("<div style='margin-top: 3rem;'></div>", unsafe_allow_html=True)
1090
 
1091
- with st.expander("💡 วิธีใช้งาน"):
1092
- st.markdown("""
1093
- 1. **เลือกแหล่งข้อมูล** ที่ sidebar ซ้าย — ใช้ไฟล์ตัวอย่าง หรืออัปโหลด Excel ของคุณเอง
1094
- 2. **เลือกประเภทแบบฟอร์ม** ที่ต้องการสร้าง (5 แบบ)
1095
- 3. **ใส่เลข PO** แล้วกด **🔍 ดึงข้อมูล** → ระบบจะดึง Vendor / ชื่องาน อัตโนมัติ
1096
- 4. **กรอกข้อมูลที่เหลือ** — หมายเลขเอกสาร, ประเภท, ผู้ลงนาม
1097
- 5. **กด ✨ สร้างเอกสาร** → **⬇ ดาวน์โหลด** ไฟล์ .docx ที่สร้างเสร็จ
1098
-
1099
- **Tip:** เก็บไฟล์ Excel ของคุณให้มีคอลัมน์ `poNo`, `VendorName`, `title` เป็นอย่างน้อย
1100
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # -*- coding: utf-8 -*-
2
  """
3
+ ระบบสร้างเอกสารอัตโนมัติ - Forest Night Dark Theme
4
+ ====================================================
5
+ - Dark forest theme (emerald + teal accents)
6
+ - No sidebar — full-width main content
7
+ - Compact inline data source picker
8
+ - Glassmorphism dark cards
 
 
 
9
  """
10
 
11
  import os
 
92
  # =============================================================================
93
  st.set_page_config(
94
  page_title="Auto Form Generator",
95
+ page_icon="🌲",
96
  layout="wide",
97
+ initial_sidebar_state="collapsed",
98
  )
99
 
100
 
101
  # =============================================================================
102
+ # Forest Night CSS Theme
103
  # =============================================================================
104
  st.markdown("""
105
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Sarabun:wght@400;500;600;700&display=swap" rel="stylesheet">
106
 
107
  <style>
108
+ /* ─── COLORS ─────────────────────────────────────────────────────
109
+ BG primary : #0F1F1E (deep forest)
110
+ BG card : #182B29 (lighter forest)
111
+ BG card alt : #1F3735
112
+ Text primary : #ECFDF5
113
+ Text secondary: #A7F3D0
114
+ Text muted : #6B8A85
115
+ Accent emerald: #10B981
116
+ Accent teal : #14B8A6
117
+ Border : rgba(16, 185, 129, 0.15)
118
+ ──────────────────────────────────────────────────────────────── */
119
 
120
+ /* GLOBAL */
121
+ html, body, [class*="css"], .stApp {
122
+ font-family: 'Inter', 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif !important;
123
+ color: #ECFDF5 !important;
124
+ }
125
+
126
+ /* Page background — Forest Night with emerald/teal glow */
127
+ .stApp {
128
+ background:
129
+ radial-gradient(at 20% 10%, rgba(16, 185, 129, 0.15) 0px, transparent 50%),
130
+ radial-gradient(at 80% 30%, rgba(20, 184, 166, 0.18) 0px, transparent 50%),
131
+ radial-gradient(at 70% 85%, rgba(132, 204, 22, 0.10) 0px, transparent 50%),
132
+ radial-gradient(at 10% 90%, rgba(16, 185, 129, 0.12) 0px, transparent 50%),
133
+ linear-gradient(180deg, #0A1817 0%, #0F1F1E 50%, #0A1817 100%) !important;
134
+ background-attachment: fixed;
135
+ }
136
+
137
+ /* Hide Streamlit chrome */
138
  [data-testid="stToolbar"] { visibility: hidden; height: 0; position: fixed; }
139
  [data-testid="stDecoration"] { display: none; }
140
  footer { visibility: hidden; }
141
  #MainMenu { visibility: hidden; }
 
 
142
  [data-testid="stHeader"] {
143
  background: transparent !important;
144
  height: 0 !important;
145
  min-height: 0 !important;
146
  padding: 0 !important;
147
  }
148
+ [data-testid="stHeader"] > div { background: transparent !important; }
 
 
149
 
150
+ /* HIDE SIDEBAR ENTIRELY */
151
+ section[data-testid="stSidebar"] {
152
+ display: none !important;
153
+ width: 0 !important;
154
+ min-width: 0 !important;
155
+ max-width: 0 !important;
156
+ }
157
  [data-testid="collapsedControl"],
158
  [data-testid="stSidebarCollapsedControl"],
 
 
 
159
  button[kind="headerNoPadding"] {
160
  display: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  .block-container {
164
  padding-top: 1.5rem !important;
165
  padding-bottom: 4rem !important;
166
  max-width: 1200px !important;
167
  }
168
 
169
+ /* ─── ANIMATIONS ─────────────────────────────────────────────── */
 
170
  @keyframes fadeInUp {
171
  from { opacity: 0; transform: translateY(20px); }
172
  to { opacity: 1; transform: translateY(0); }
173
  }
174
  @keyframes pulse {
175
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
176
+ 50% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
 
 
 
 
177
  }
178
  @keyframes blob {
179
  0%, 100% { transform: translate(0, 0) scale(1); }
 
181
  66% { transform: translate(-20px, 20px) scale(0.9); }
182
  }
183
 
184
+ /* ─── HERO ───────────────────────────────────────────────────── */
 
185
  .hero {
186
  position: relative;
187
+ background: linear-gradient(135deg, #064E3B 0%, #047857 30%, #0F766E 65%, #155E75 100%);
188
+ padding: 2.75rem 2.5rem;
189
  border-radius: 24px;
190
+ color: #ECFDF5;
191
  margin-bottom: 2rem;
192
  overflow: hidden;
193
  box-shadow:
194
+ 0 20px 50px -15px rgba(0, 0, 0, 0.5),
195
+ 0 0 0 1px rgba(16, 185, 129, 0.2) inset;
196
  animation: fadeInUp 0.6s ease;
197
  }
 
 
198
  .hero::before {
199
  content: "";
200
  position: absolute;
201
  top: -120px;
202
  right: -80px;
203
+ width: 360px;
204
+ height: 360px;
205
+ background: radial-gradient(circle, rgba(16, 185, 129, 0.4) 0%, transparent 60%);
206
  border-radius: 50%;
207
+ animation: blob 14s ease-in-out infinite;
208
  }
209
  .hero::after {
210
  content: "";
211
  position: absolute;
212
  bottom: -100px;
213
  left: 30%;
214
+ width: 300px;
215
+ height: 300px;
216
+ background: radial-gradient(circle, rgba(20, 184, 166, 0.3) 0%, transparent 60%);
217
  border-radius: 50%;
218
+ animation: blob 18s ease-in-out infinite reverse;
219
  }
 
 
220
  .hero-pattern {
221
  position: absolute;
222
  inset: 0;
223
+ background-image: radial-gradient(circle, rgba(255,255,255,0.07) 1px, transparent 1px);
224
  background-size: 24px 24px;
225
+ opacity: 0.6;
226
  pointer-events: none;
227
  }
228
+ .hero-content { position: relative; z-index: 2; }
 
 
 
 
229
  .hero-badge {
230
  display: inline-flex;
231
  align-items: center;
232
  gap: 0.4rem;
233
+ background: rgba(16, 185, 129, 0.2);
234
  backdrop-filter: blur(10px);
235
+ border: 1px solid rgba(16, 185, 129, 0.4);
236
+ color: #6EE7B7;
237
  padding: 0.4rem 0.9rem;
238
  border-radius: 999px;
239
  font-size: 0.78rem;
 
243
  text-transform: uppercase;
244
  }
245
  .hero h1 {
246
+ color: #ECFDF5 !important;
247
  font-size: 2.75rem !important;
248
  font-weight: 800 !important;
249
  margin: 0 0 0.75rem 0 !important;
 
251
  line-height: 1.1 !important;
252
  }
253
  .hero-subtitle {
254
+ color: rgba(236, 253, 245, 0.85) !important;
255
  font-size: 1.05rem !important;
256
  font-weight: 400 !important;
257
+ max-width: 600px;
258
  line-height: 1.5;
259
  }
 
 
260
  .hero-stats {
261
+ display: flex; gap: 2rem; margin-top: 1.75rem; flex-wrap: wrap;
 
 
 
 
 
 
 
262
  }
263
  .hero-stat-value {
264
+ font-size: 1.5rem; font-weight: 700; color: #ECFDF5; line-height: 1;
 
 
 
265
  }
266
  .hero-stat-label {
267
  font-size: 0.75rem;
268
+ color: rgba(167, 243, 208, 0.85);
269
  text-transform: uppercase;
270
  letter-spacing: 0.06em;
271
  margin-top: 0.25rem;
272
  }
273
 
274
+ /* ─── DATA SOURCE BAR (replaces sidebar) ─────────────────────── */
275
+ .source-bar {
276
+ background: rgba(20, 184, 166, 0.08);
277
+ backdrop-filter: blur(20px);
278
+ border: 1px solid rgba(16, 185, 129, 0.18);
279
+ border-radius: 14px;
280
+ padding: 0.7rem 1.1rem;
281
+ margin-bottom: 1.5rem;
282
+ display: flex;
283
+ align-items: center;
284
+ gap: 0.85rem;
285
+ animation: fadeInUp 0.6s ease 0.05s both;
286
+ flex-wrap: wrap;
287
+ }
288
+ .source-icon {
289
+ width: 32px; height: 32px;
290
+ border-radius: 10px;
291
+ background: rgba(16, 185, 129, 0.18);
292
+ display: flex; align-items: center; justify-content: center;
293
+ font-size: 1rem;
294
+ }
295
+ .source-label {
296
+ color: #A7F3D0;
297
+ font-size: 0.8rem;
298
+ font-weight: 500;
299
+ }
300
+ .source-value {
301
+ color: #ECFDF5;
302
+ font-size: 0.9rem;
303
+ font-weight: 600;
304
+ }
305
 
306
+ /* ─── STEPS ──────────────────────────────────────────────────── */
307
  .steps-wrapper {
308
+ background: rgba(255, 255, 255, 0.03);
309
  backdrop-filter: blur(20px);
310
+ border: 1px solid rgba(16, 185, 129, 0.15);
 
311
  border-radius: 16px;
312
  padding: 1.25rem 1.5rem;
313
  margin-bottom: 2rem;
 
314
  animation: fadeInUp 0.6s ease 0.1s both;
315
  }
316
+ .steps-row { display: flex; align-items: center; gap: 0; }
317
+ .step { display: flex; align-items: center; gap: 0.7rem; flex: 0 0 auto; }
 
 
 
 
 
 
 
 
 
 
318
  .step-circle {
319
+ width: 40px; height: 40px; border-radius: 50%;
320
+ display: flex; align-items: center; justify-content: center;
321
+ font-weight: 700; font-size: 1rem;
 
 
 
 
 
322
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
 
 
323
  }
324
  .step-default .step-circle {
325
+ background: rgba(255, 255, 255, 0.05);
326
+ color: #6B8A85;
327
+ border: 2px solid rgba(255, 255, 255, 0.08);
328
  }
329
  .step-active .step-circle {
330
+ background: linear-gradient(135deg, #10B981 0%, #14B8A6 100%);
331
  color: white;
332
+ box-shadow: 0 4px 16px rgba(16, 185, 129, 0.5);
333
  animation: pulse 2s infinite;
334
  }
335
  .step-done .step-circle {
336
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
337
  color: white;
338
+ box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
339
  }
340
+ .step-label { font-size: 0.85rem; font-weight: 500; color: #6B8A85; white-space: nowrap; }
341
+ .step-active .step-label { color: #6EE7B7; font-weight: 600; }
342
+ .step-done .step-label { color: #34D399; font-weight: 600; }
 
 
 
 
 
343
 
 
344
  .step-bar {
345
+ flex: 1; height: 3px;
346
+ background: rgba(255, 255, 255, 0.08);
347
+ margin: 0 1rem; border-radius: 999px;
348
+ overflow: hidden; position: relative;
 
 
 
349
  }
350
  .step-bar-fill {
351
+ position: absolute; inset: 0;
 
352
  background: linear-gradient(90deg, #10B981 0%, #059669 100%);
353
  transform-origin: left;
354
  transition: transform 0.5s ease;
355
  }
356
+ .step-bar-fill.empty { transform: scaleX(0); }
357
+ .step-bar-fill.full { transform: scaleX(1); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
 
359
+ /* ─── CARDS ──────────────────────────────────────────────────── */
360
  .card-header {
361
+ display: flex; align-items: center; gap: 0.75rem;
 
 
362
  margin-bottom: 1.25rem;
363
  }
364
  .card-icon {
365
+ width: 40px; height: 40px;
 
366
  border-radius: 12px;
367
+ display: flex; align-items: center; justify-content: center;
 
 
368
  font-size: 1.25rem;
369
  }
370
+ .card-icon-1 { background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(20, 184, 166, 0.15) 100%); }
371
+ .card-icon-2 { background: linear-gradient(135deg, rgba(20, 184, 166, 0.2) 0%, rgba(6, 182, 212, 0.15) 100%); }
372
  .card-title {
373
+ font-size: 1.1rem; font-weight: 700; color: #ECFDF5; margin: 0; line-height: 1.2;
 
 
 
 
374
  }
375
  .card-subtitle {
376
+ font-size: 0.8rem; color: #6B8A85; margin: 0.15rem 0 0 0; font-weight: 500;
 
 
 
377
  }
378
 
379
+ /* ─── VENDOR CARDS ───────────────────────────────────────────── */
 
380
  .vendor-card {
381
+ background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(20, 184, 166, 0.06) 100%);
382
+ border: 1px solid rgba(16, 185, 129, 0.2);
383
  padding: 1rem 1.25rem;
384
  border-radius: 14px;
385
  margin: 0.6rem 0;
 
389
  }
390
  .vendor-card:hover {
391
  transform: translateX(2px);
392
+ box-shadow: 0 4px 16px rgba(16, 185, 129, 0.15);
393
  }
394
  .vendor-card::before {
395
  content: "";
396
  position: absolute;
397
+ left: 0; top: 0; bottom: 0;
 
 
398
  width: 4px;
399
+ background: linear-gradient(180deg, #10B981 0%, #14B8A6 100%);
400
  }
401
  .vendor-card-label {
402
  font-size: 0.7rem;
403
  text-transform: uppercase;
404
+ color: #6EE7B7;
405
  font-weight: 700;
406
  letter-spacing: 0.06em;
407
  margin-bottom: 0.4rem;
408
+ display: flex; align-items: center; gap: 0.4rem;
 
 
409
  }
410
  .vendor-card-value {
411
  font-size: 1.05rem;
412
+ color: #ECFDF5;
413
  font-weight: 600;
414
  line-height: 1.4;
415
  }
416
 
417
+ /* ─── BUTTONS ────────────────────────────────────────────────── */
 
 
418
  .stButton button[kind="primary"] {
419
+ background: linear-gradient(135deg, #10B981 0%, #14B8A6 50%, #06B6D4 100%) !important;
420
  background-size: 200% 200% !important;
421
  border: none !important;
422
+ color: white !important;
423
  box-shadow:
424
+ 0 4px 20px rgba(16, 185, 129, 0.4),
425
+ 0 0 0 1px rgba(16, 185, 129, 0.3) inset !important;
426
  font-weight: 700 !important;
427
  height: 3.25rem !important;
428
  font-size: 1.05rem !important;
 
429
  transition: all 0.3s ease !important;
430
  border-radius: 12px !important;
431
  }
432
  .stButton button[kind="primary"]:hover {
433
  transform: translateY(-2px);
434
  box-shadow:
435
+ 0 8px 28px rgba(16, 185, 129, 0.55),
436
+ 0 0 0 1px rgba(16, 185, 129, 0.5) inset !important;
437
  background-position: 100% 100% !important;
438
  }
 
 
 
 
 
439
  .stButton button[kind="secondary"] {
440
+ background: rgba(16, 185, 129, 0.08) !important;
441
+ border: 1.5px solid rgba(16, 185, 129, 0.3) !important;
442
+ color: #6EE7B7 !important;
443
  font-weight: 600 !important;
444
  height: 3rem !important;
445
  border-radius: 12px !important;
446
  transition: all 0.2s ease !important;
447
  }
448
  .stButton button[kind="secondary"]:hover {
449
+ background: rgba(16, 185, 129, 0.15) !important;
450
+ border-color: #10B981 !important;
451
  transform: translateY(-1px);
452
  }
 
 
453
  .stDownloadButton button {
454
  background: linear-gradient(135deg, #10B981 0%, #059669 100%) !important;
455
  color: white !important;
456
  border: none !important;
457
+ box-shadow: 0 4px 20px rgba(16, 185, 129, 0.45) !important;
458
  font-weight: 700 !important;
459
  height: 3.25rem !important;
460
  font-size: 1.05rem !important;
 
463
  }
464
  .stDownloadButton button:hover {
465
  transform: translateY(-2px);
466
+ box-shadow: 0 8px 28px rgba(16, 185, 129, 0.55) !important;
467
  }
468
 
469
+ /* ─── INPUTS ─────────────────────────────────────────────────── */
 
470
  .stTextInput input,
 
471
  .stTextArea textarea {
472
+ background: rgba(255, 255, 255, 0.04) !important;
473
+ border: 1.5px solid rgba(16, 185, 129, 0.18) !important;
474
+ color: #ECFDF5 !important;
475
  border-radius: 12px !important;
 
 
476
  font-size: 0.95rem !important;
477
  }
478
+ .stTextInput input::placeholder,
479
+ .stTextArea textarea::placeholder {
480
+ color: rgba(167, 243, 208, 0.4) !important;
481
+ }
482
  .stTextInput input:focus,
483
  .stTextArea textarea:focus {
484
+ border-color: #10B981 !important;
485
+ box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15) !important;
486
+ }
487
+
488
+ /* Selectbox */
489
+ .stSelectbox > div > div {
490
+ background: rgba(255, 255, 255, 0.04) !important;
491
+ border: 1.5px solid rgba(16, 185, 129, 0.18) !important;
492
+ color: #ECFDF5 !important;
493
+ border-radius: 12px !important;
494
+ }
495
+ .stSelectbox [data-baseweb="select"] > div {
496
+ color: #ECFDF5 !important;
497
+ }
498
+
499
+ /* Radio buttons */
500
+ .stRadio label {
501
+ color: #ECFDF5 !important;
502
+ }
503
+ .stRadio [data-baseweb="radio"] {
504
+ color: #ECFDF5 !important;
505
+ }
506
+
507
+ /* File uploader */
508
+ [data-testid="stFileUploader"] {
509
+ background: rgba(255, 255, 255, 0.03) !important;
510
+ border: 2px dashed rgba(16, 185, 129, 0.3) !important;
511
+ border-radius: 14px !important;
512
+ color: #ECFDF5 !important;
513
+ }
514
+ [data-testid="stFileUploader"] section {
515
+ background: transparent !important;
516
+ }
517
+ [data-testid="stFileUploader"] small {
518
+ color: #6B8A85 !important;
519
  }
520
 
521
  /* Labels */
 
524
  .stRadio label,
525
  .stFileUploader label {
526
  font-weight: 600 !important;
527
+ color: #A7F3D0 !important;
528
  font-size: 0.85rem !important;
529
  }
530
 
531
+ /* ─── ALERTS ─────────────────────────────────────────────────── */
 
 
 
 
 
 
 
 
 
 
 
532
  .stAlert {
533
  border-radius: 14px !important;
534
  border: none !important;
535
  backdrop-filter: blur(10px);
536
  }
537
+ [data-testid="stNotificationContentSuccess"] {
538
+ background: rgba(16, 185, 129, 0.15) !important;
539
+ color: #6EE7B7 !important;
540
+ }
541
+ [data-testid="stNotificationContentInfo"] {
542
+ background: rgba(20, 184, 166, 0.15) !important;
543
+ color: #99F6E4 !important;
544
+ }
545
+ [data-testid="stNotificationContentWarning"] {
546
+ background: rgba(245, 158, 11, 0.15) !important;
547
+ color: #FCD34D !important;
548
+ }
549
+ [data-testid="stNotificationContentError"] {
550
+ background: rgba(239, 68, 68, 0.15) !important;
551
+ color: #FCA5A5 !important;
552
+ }
553
 
554
+ /* ─── EXPANDERS ──────────────────────────────────────────────── */
555
+ .streamlit-expanderHeader,
556
+ [data-testid="stExpander"] summary {
557
+ background: rgba(255, 255, 255, 0.03) !important;
558
+ border-radius: 12px !important;
559
+ color: #A7F3D0 !important;
560
+ font-weight: 600 !important;
561
+ border: 1px solid rgba(16, 185, 129, 0.12) !important;
562
+ }
563
+ [data-testid="stExpander"] {
564
+ background: transparent !important;
565
+ border: none !important;
566
+ }
567
+ [data-testid="stExpander"] details {
568
+ background: transparent !important;
569
+ border: none !important;
570
+ }
571
+ [data-testid="stExpander"] [data-testid="stExpanderDetails"] {
572
+ background: rgba(255, 255, 255, 0.02) !important;
573
+ border: 1px solid rgba(16, 185, 129, 0.1) !important;
574
+ border-radius: 12px !important;
575
+ padding: 1rem !important;
576
+ margin-top: 0.5rem !important;
577
+ }
578
 
579
+ /* ─── SECTION TITLE ──────────────────────────────────────────── */
580
  .section-title {
581
  font-size: 0.95rem;
582
  font-weight: 700;
583
+ color: #ECFDF5;
584
  margin: 1.25rem 0 0.75rem 0;
585
+ display: flex; align-items: center; gap: 0.5rem;
 
 
586
  }
587
  .section-title::before {
588
  content: "";
589
+ width: 4px; height: 18px;
590
+ background: linear-gradient(180deg, #10B981 0%, #14B8A6 100%);
 
591
  border-radius: 2px;
592
  }
593
 
594
+ /* ─── EMPTY STATE ────────────────────────────────────────────── */
 
595
  .empty-state {
596
  text-align: center;
597
  padding: 2rem 1rem;
598
+ background: rgba(255, 255, 255, 0.02);
599
  border-radius: 14px;
600
+ border: 2px dashed rgba(16, 185, 129, 0.2);
601
  margin: 1rem 0;
602
  }
603
+ .empty-state-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.5; }
604
+ .empty-state-text { color: #6B8A85; font-size: 0.9rem; margin: 0; }
 
 
 
 
 
 
 
 
 
 
605
 
606
+ /* ─── DIVIDER ─────────────────────────────────────────────────── */
607
  hr {
608
  border: none !important;
609
  height: 1px !important;
610
+ background: linear-gradient(90deg, transparent 0%, rgba(16, 185, 129, 0.25) 50%, transparent 100%) !important;
611
  margin: 1rem 0 !important;
612
  }
613
+
614
+ /* Captions */
615
+ .caption, .stCaption, [data-testid="stCaptionContainer"] {
616
+ color: #6B8A85 !important;
617
+ }
618
+
619
+ /* Markdown content (general text) */
620
+ .stMarkdown, .stMarkdown p, [data-testid="stMarkdownContainer"] {
621
+ color: #ECFDF5 !important;
622
+ }
623
+ .stMarkdown strong { color: #6EE7B7 !important; }
624
+ .stMarkdown code {
625
+ background: rgba(16, 185, 129, 0.12) !important;
626
+ color: #6EE7B7 !important;
627
+ padding: 0.15rem 0.45rem !important;
628
+ border-radius: 6px !important;
629
+ }
630
+
631
+ /* Spinner */
632
+ .stSpinner > div {
633
+ border-top-color: #10B981 !important;
634
+ }
635
  </style>
636
  """, unsafe_allow_html=True)
637
 
 
644
  ("last_po", ""),
645
  ("generated_file", None),
646
  ("generated_filename", None),
647
+ ("use_uploaded_excel", False),
648
+ ("uploaded_excel_bytes", None),
649
+ ("uploaded_excel_name", ""),
650
  ]:
651
  if key not in st.session_state:
652
  st.session_state[key] = default
653
 
654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  # =============================================================================
656
  # Hero Section
657
  # =============================================================================
 
660
  <div class="hero-pattern"></div>
661
  <div class="hero-content">
662
  <div class="hero-badge">
663
+ 🌲 Auto Document Generator
664
  </div>
665
  <h1>Auto Form Generator</h1>
666
  <p class="hero-subtitle">
 
687
 
688
 
689
  # =============================================================================
690
+ # Data Source Bar (replaces sidebar)
691
+ # =============================================================================
692
+ sample_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
693
+ 'sample_po_data.xlsx')
694
+
695
+ # Determine current data source
696
+ excel_bytes = None
697
+ if st.session_state.use_uploaded_excel and st.session_state.uploaded_excel_bytes:
698
+ excel_bytes = st.session_state.uploaded_excel_bytes
699
+ source_text = f"📁 ไฟล์ของคุณ: {st.session_state.uploaded_excel_name}"
700
+ else:
701
+ if os.path.exists(sample_path):
702
+ with open(sample_path, 'rb') as f:
703
+ excel_bytes = f.read()
704
+ source_text = "🎯 ใช้ไฟล์ตัวอย่าง · ลอง PO 4500987654 / 4500987655 / 4500987656"
705
+
706
+ src_col1, src_col2 = st.columns([4, 1])
707
+ with src_col1:
708
+ st.markdown(f"""
709
+ <div class="source-bar">
710
+ <div class="source-icon">📊</div>
711
+ <div>
712
+ <div class="source-label">แหล่งข้อมูล Excel</div>
713
+ <div class="source-value">{source_text}</div>
714
+ </div>
715
+ </div>
716
+ """, unsafe_allow_html=True)
717
+ with src_col2:
718
+ st.markdown("<div style='height: 0.85rem'></div>", unsafe_allow_html=True)
719
+ if st.session_state.use_uploaded_excel:
720
+ if st.button("🔄 ใช้ตัวอย่าง", use_container_width=True, type="secondary"):
721
+ st.session_state.use_uploaded_excel = False
722
+ st.session_state.uploaded_excel_bytes = None
723
+ st.session_state.uploaded_excel_name = ""
724
+ st.rerun()
725
+ else:
726
+ if st.button("📁 อัปโหลด", use_container_width=True, type="secondary"):
727
+ st.session_state.show_uploader = True
728
+ st.rerun()
729
+
730
+ # Show uploader inline if requested
731
+ if st.session_state.get("show_uploader") and not st.session_state.use_uploaded_excel:
732
+ upload_col = st.container()
733
+ with upload_col:
734
+ uploaded = st.file_uploader("เลือกไฟล์ Excel (.xlsx)",
735
+ type=['xlsx'],
736
+ accept_multiple_files=False,
737
+ key="excel_uploader")
738
+ if uploaded:
739
+ st.session_state.uploaded_excel_bytes = uploaded.read()
740
+ st.session_state.uploaded_excel_name = uploaded.name
741
+ st.session_state.use_uploaded_excel = True
742
+ st.session_state.show_uploader = False
743
+ excel_bytes = st.session_state.uploaded_excel_bytes
744
+ st.rerun()
745
+
746
+
747
+ # =============================================================================
748
+ # Step Indicator (reacts to current form state)
749
  # =============================================================================
750
  has_lookup = bool(st.session_state.lookup_data)
751
  has_file = bool(st.session_state.generated_file)
752
 
 
 
753
  cur_po = st.session_state.get("po_input_widget", "") or ""
754
  cur_doc = st.session_state.get("doc_number_widget", "") or ""
755
  cur_signer = st.session_state.get("signer_widget", "") or ""
756
  cur_form = st.session_state.get("form_select_widget", FORM_TYPES[0]["label"])
757
 
 
758
  inputs_match_snapshot = (
759
  cur_po.strip() == st.session_state.get("last_gen_po", "") and
760
  cur_doc.strip() == st.session_state.get("last_gen_doc", "") and
761
  cur_signer.strip() == st.session_state.get("last_gen_signer", "") and
762
  cur_form == st.session_state.get("last_gen_form", "")
763
  )
 
 
764
  has_generated = has_file and inputs_match_snapshot
765
 
766
  if has_generated:
 
840
  if not po_number.strip():
841
  st.warning("⚠ กรุณากรอกเลข PO ก่อน")
842
  elif not excel_bytes:
843
+ st.error("ไม่มีไฟล์ Excel")
844
  else:
845
  with st.spinner("กำลังค้นหา..."):
846
  try:
847
  result, available_cols = lookup_po_in_bytes(
848
  po_number.strip(), excel_bytes,
849
+ sheet_name=st.session_state.get("adv_sheet_name", "") or None,
850
+ po_column=st.session_state.get("adv_po_column", "poNo").strip() or "poNo",
851
  )
852
  if isinstance(result, dict) and "__error__" in result:
853
  st.error(result["__error__"])
 
865
  except Exception as e:
866
  st.error(f"❌ ผิดพลาด: {e}")
867
 
 
868
  if st.session_state.lookup_data:
869
  st.markdown('<div class="section-title">ข้อมูลที่ดึงจาก Excel</div>',
870
  unsafe_allow_html=True)
 
989
 
990
  st.session_state.generated_file = output_bytes
991
  st.session_state.generated_filename = filename
 
 
992
  st.session_state.last_gen_po = po_number.strip()
993
  st.session_state.last_gen_doc = doc_number.strip()
994
  st.session_state.last_gen_signer = signer.strip()
 
997
  except Exception as e:
998
  st.error(f"❌ ไม่สามารถสร้างเอกสารได้: {e}")
999
 
 
1000
  if st.session_state.generated_file:
1001
  st.markdown("<div style='height: 0.75rem;'></div>", unsafe_allow_html=True)
1002
  st.markdown("""
1003
+ <div style="background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(20, 184, 166, 0.10) 100%);
1004
+ border: 1px solid rgba(16, 185, 129, 0.4); padding: 0.85rem 1rem; border-radius: 14px;
1005
  margin-bottom: 0.75rem;">
1006
  <div style="display: flex; align-items: center; gap: 0.5rem;">
1007
+ <span style="background: linear-gradient(135deg, #10B981, #14B8A6); color: white; width: 24px; height: 24px;
1008
  border-radius: 50%; display: inline-flex; align-items: center;
1009
  justify-content: center; font-size: 0.85rem;">✓</span>
1010
+ <span style="font-weight: 600; color: #6EE7B7;">สร้างเอกสารสำเร็จ!</span>
1011
  </div>
1012
  </div>
1013
  """, unsafe_allow_html=True)
 
1022
 
1023
 
1024
  # =============================================================================
1025
+ # Footer — Help + Advanced Settings
1026
  # =============================================================================
1027
  st.markdown("<div style='margin-top: 3rem;'></div>", unsafe_allow_html=True)
1028
 
1029
+ footer_col1, footer_col2 = st.columns(2)
1030
+
1031
+ with footer_col1:
1032
+ with st.expander("💡 วิธีใช้งาน"):
1033
+ st.markdown("""
1034
+ 1. **เลือกประเภทแบบฟอร์ม** ที่ต้องการสร้าง (5 แบบ)
1035
+ 2. **ใส่เลข PO** แล้วกด **🔍 ดึงข้อมูล** → ระบบจะดึง Vendor / ชื่องาน อัตโนมัติ
1036
+ 3. **กรอกข้อมูลที่เหลือ** — หมายเลขเอกสาร, ประเภท, ผู้ลงนาม
1037
+ 4. **กด ✨ สร้างเอกสาร** → **⬇ ดาวน์โหลด** ไฟล์ .docx
1038
+
1039
+ **Tip:** Excel ของคุณต้องมีคอลัมน์ `poNo`, `VendorName`, `title` เป็นอย่างน้อย
1040
+ """)
1041
+
1042
+ with footer_col2:
1043
+ with st.expander("⚙️ ตั้งค่าขั้นสูง"):
1044
+ st.text_input("ชื่อคอลัมน์ PO ใน Excel",
1045
+ value="poNo",
1046
+ key="adv_po_column",
1047
+ help="ปกติคอลัมน์ชื่อ `poNo`")
1048
+ st.text_input("ชื่อ Sheet",
1049
+ value="",
1050
+ key="adv_sheet_name",
1051
+ help="เว้นว่าง = ใช้ sheet แรกของไฟล์")
1052
+
1053
+ st.markdown("""
1054
+ <div style="text-align: center; margin-top: 2rem; color: #4A6B68; font-size: 0.75rem;">
1055
+ Made with 🌲 for ปตท. · Streamlit · Hugging Face Spaces
1056
+ </div>
1057
+ """, unsafe_allow_html=True)