Kietcudo commited on
Commit
e1cdcfb
·
verified ·
1 Parent(s): d1359e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -71
app.py CHANGED
@@ -357,6 +357,9 @@ def chatbot_response(user_message, history):
357
 
358
  # --- MÃ JS ANIMATION CHIẾC LÁ ---
359
  LEAF_HERO_HEAD = r"""
 
 
 
360
  <script>
361
  (function () {
362
  "use strict";
@@ -403,22 +406,31 @@ LEAF_HERO_HEAD = r"""
403
  leaves: LEAF_CASES, cycleSeconds: 16, trailCycles: 2.6, compress: 0.42,
404
  maxTurns: 3, planeSpread: 1, eccentricity: 0.25, alignToCourse: 1,
405
  driftSpeed: 1.5, driftDir: [272, 53], viewRadius: 3.1, tilt: 45, spin: 252, roll: 13.5,
406
- lead: 0.12, focus: [0.74, 0.42], scrim: "left", scrimStrength: 0.88,
407
- moteCount: 400, glow: 1, showCoreBeam: true, interactive: true, crossColor: "#2d7a12"
 
408
  };
 
 
409
 
410
  function applyResponsive() {
411
- const narrow = window.innerWidth <= 767;
412
- C.focus = narrow ? [0.5, 0.86] : [0.66, 0.55];
 
 
 
 
 
 
413
  C.scrim = narrow ? "top" : "left";
414
- C.scrimStrength = narrow ? 0.90 : 0.88;
415
- C.viewRadius = narrow ? 2.1 : 3.1;
416
  C.lead = narrow ? 0.05 : 0.12;
417
- C.glow = narrow ? 0.6 : 1;
418
  }
419
  applyResponsive();
420
 
421
- let width=0, height=0, dpr=1, years=0, lastFrame=0, pxPerAU=1, cx=0, cy=0, camDist=1;
422
  const RIGHT={x:1,y:0,z:0}, UP={x:0,y:1,z:0}, FWD={x:0,y:0,z:1};
423
 
424
  function setCamera(yaw,pitch,roll) {
@@ -539,25 +551,65 @@ LEAF_HERO_HEAD = r"""
539
  pointerX = (ev.clientX / window.innerWidth - 0.5) * 2; pointerY = (ev.clientY / window.innerHeight - 0.5) * 2;
540
  });
541
 
542
- function drawCross(k, t) {
543
- const [r, g, b] = parseRGB(C.crossColor), pulse = 1 + Math.sin(t * 2.1) * 0.015, baseR = Math.max(30, Math.min(width, height) * 0.066) * pulse;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
544
  const haze = ctx.createRadialGradient(cx, cy, 0, cx, cy, baseR * 4);
545
  haze.addColorStop(0, `rgba(${r},${g},${b},${0.12 * k})`); haze.addColorStop(0.4, `rgba(${r},${g},${b},${0.04 * k})`); haze.addColorStop(1, `rgba(${r},${g},${b},0)`);
546
  ctx.fillStyle = haze; ctx.beginPath(); ctx.arc(cx, cy, baseR * 4, 0, TAU); ctx.fill();
547
- // Mid glow — quầng sáng lớp giữa
548
  const mid = ctx.createRadialGradient(cx, cy, 0, cx, cy, baseR * 2);
549
- mid.addColorStop(0, `rgba(${r},${g},${b},${0.26 * k})`);
550
- mid.addColorStop(0.5, `rgba(${r},${g},${b},${0.08 * k})`);
551
- mid.addColorStop(1, `rgba(${r},${g},${b},0)`);
552
- ctx.fillStyle = mid;
553
- ctx.beginPath(); ctx.arc(cx, cy, baseR * 2, 0, TAU); ctx.fill();
554
- // Ring sáng viền badge
555
- ctx.strokeStyle = `rgba(255,255,255,0.22)`;
556
- ctx.lineWidth = 2;
557
- ctx.beginPath(); ctx.arc(cx, cy, baseR * 0.95 + 3, 0, TAU); ctx.stroke();
558
  const badgeR = baseR * 0.95, badge = ctx.createRadialGradient(cx, cy - badgeR * 0.15, badgeR * 0.2, cx, cy, badgeR);
559
  badge.addColorStop(0, "#8fcb5e"); badge.addColorStop(1, "#3c8b22");
560
  ctx.fillStyle = badge; ctx.beginPath(); ctx.arc(cx, cy, badgeR, 0, TAU); ctx.fill();
 
 
 
561
  const armLen = badgeR * 0.6, armW = badgeR * 0.22, rad = armW * 0.45;
562
  ctx.fillStyle = "#fff";
563
  ctx.beginPath(); ctx.roundRect(cx - armW, cy - armLen, armW * 2, armLen * 2, rad); ctx.fill();
@@ -574,7 +626,7 @@ LEAF_HERO_HEAD = r"""
574
  }
575
 
576
  function render(t) {
577
- const k = C.glow; layout(); syncElements();
578
  camX += (pointerX - camX) * 0.04; camY += (pointerY - camY) * 0.04;
579
  setCamera(C.spin + camX * 7, C.tilt + camY * 5, C.roll);
580
  dist = C.driftSpeed * t; cx = width * C.focus[0]; cy = height * C.focus[1];
@@ -597,25 +649,19 @@ LEAF_HERO_HEAD = r"""
597
  });
598
  ctx.setLineDash([]);
599
  const dRef = D_NEAR * 3.3, left = -width * 0.12, right = width * 1.12, top = -height * 0.12, bottom = height * 1.12;
600
- for (let s = 0; s < starN; s++) {
601
  project(sx[s] - DIR.x * dist, sy[s] - DIR.y * dist, sz[s] - DIR.z * dist);
602
  if (!P.ok || P.depth > D_FAR * 1.25) { seedStar(s); continue; }
603
  if (P.x < left || P.x > right || P.y < top || P.y > bottom) { seedStar(s, undefined, P.x < left ? 1 : P.x > right ? 0 : P.y < top ? 3 : 2); continue; }
604
  if (P.depth < D_NEAR * 0.75) continue;
605
  const near = Math.min(1, (P.depth - D_NEAR * 0.75) / (D_NEAR * 0.6));
606
  const far = 1 - Math.max(0, (P.depth - D_FAR * 0.78) / (D_FAR * 0.32));
607
- let a = (0.28 + sMag[s] * 1.05) * Math.pow(dRef / P.depth, 0.8) * near * far;
608
  if (a <= 0.01) continue;
609
- // Twinkle mạnh — biên độ 0.55, tạo cảm giác chớp sáng như sao
610
- a *= 0.45 + 0.55 * Math.pow(0.5 + 0.5 * Math.sin(t * 6.5 + sPhase[s]), 2);
611
- const col = sTint[s] === 1 ? "170,205,110" : sTint[s] === 2 ? "60,130,50" : "95,170,85";
612
- const size = Math.min(4.2, 1.1 + sMag[s] * 3.2 * Math.pow(dRef / P.depth, 0.5));
613
- ctx.globalAlpha = Math.min(0.88, a);
614
- // Halo lấp lánh cho hạt lớn
615
- if (size >= 1.6) {
616
- ctx.fillStyle = `rgba(${col},${(a * 0.35).toFixed(3)})`;
617
- ctx.beginPath(); ctx.arc(P.x, P.y, size * 1.6, 0, TAU); ctx.fill();
618
- }
619
  ctx.fillStyle = `rgb(${col})`;
620
  if (size < 1.2) ctx.fillRect(P.x, P.y, size, size);
621
  else { ctx.beginPath(); ctx.arc(P.x, P.y, size * 0.5, 0, TAU); ctx.fill(); }
@@ -661,7 +707,9 @@ LEAF_HERO_HEAD = r"""
661
 
662
  let idx = 0;
663
  while (idx < shots.length && shots[idx].depth > camDist) drawShot(shots[idx], idx++);
664
- drawCross(k, t);
 
 
665
  while (idx < shots.length) drawShot(shots[idx], idx++);
666
  drawBorderLeaves(t);
667
 
@@ -679,6 +727,7 @@ LEAF_HERO_HEAD = r"""
679
  if (!active || document.hidden) { lastFrame = now; return; }
680
  const dt = lastFrame ? Math.min(0.05, (now - lastFrame) / 1000) : 0;
681
  lastFrame = now;
 
682
  years += dt / Math.max(0.1, C.cycleSeconds);
683
  render(years);
684
  }
@@ -706,63 +755,91 @@ LEAF_HERO_HEAD = r"""
706
  """
707
 
708
  custom_css = """
709
- /* ===================== LEAF HERO LOGIN ===================== */
710
  #leaf-bg {
711
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0;
712
  opacity: 0; pointer-events: none; transition: opacity 0.6s ease;
713
  }
714
  body.leaf-on #leaf-bg { opacity: 1; }
715
- body.leaf-on { background: #e8f5d6 !important; margin: 0; padding: 0; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
716
- body.leaf-on .gradio-container { background: transparent !important; }
 
 
717
 
718
  #login_wrapper {
719
  position: relative; z-index: 2; min-height: 100vh;
720
  display: flex !important; align-items: center !important;
721
- padding: 0 6vw !important; box-sizing: border-box;
722
  }
723
  #login_wrapper.hide { display: none !important; }
724
 
 
725
  #login_content_col {
726
- max-width: 34rem !important; margin-left: 10% !important;
727
- background: rgba(255, 255, 255, 0.45);
728
- padding: 35px 30px; border-radius: 24px;
729
- backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.7);
730
- box-shadow: 0 20px 40px rgba(45, 122, 18, 0.08);
731
  }
732
  @media (max-width: 767px) {
733
- #login_content_col { margin-left: 0 !important; width: 100% !important; padding: 25px; }
 
734
  }
735
 
736
- .badge { display: inline-flex; align-items: center; border-radius: 999px; border: 1.5px solid rgba(60,120,30,0.3); background: rgba(255,255,255,0.55); padding: 6px 14px; font-size: 12px; letter-spacing: 0.05em; color: #3c6b1f; font-weight: 600; margin-bottom: 5px; }
737
- #login_wrapper h1 { margin: 15px 0 0; font-weight: 300; line-height: 1.1; letter-spacing: -0.02em; color: #1a3a0a; font-size: clamp(2rem, 4.4vw, 3.75rem); }
738
- #login_wrapper h1 em { font-style: italic; color: #2d7a12; }
739
- #login_wrapper p.sub { margin: 24px 0 30px 0; max-width: 28rem; font-size: 0.95rem; line-height: 1.7; color: rgba(30,60,15,0.7); }
740
-
 
 
 
 
 
 
 
 
 
 
 
 
 
741
  #login_wrapper .gr-form, #login_wrapper .block, #login_wrapper .form { background: transparent !important; border: none !important; box-shadow: none !important; }
742
- #login_wrapper label span, #login_wrapper .gr-box label { color: #2d7a12 !important; font-size: 13px !important; font-weight: 600 !important; letter-spacing: .02em !important; }
743
  #login_wrapper input[type="text"], #login_wrapper input[type="password"] {
744
- background: rgba(255,255,255,0.7) !important; border: 1.5px solid rgba(45,122,18,0.3) !important;
745
- border-radius: 12px !important; color: #1a3a0a !important; font-size: 15px !important; min-height: 48px !important;
746
- padding: 0 16px !important; transition: all 0.2s ease !important;
 
747
  }
748
- #login_wrapper input::placeholder { color: rgba(30,60,15,0.4) !important; }
749
- #login_wrapper input:hover { background: rgba(255,255,255,0.9) !important; }
750
  #login_wrapper input:focus, #login_wrapper input:focus-visible {
751
- border-color: #2d7a12 !important; background: #fff !important; outline: none !important;
752
- box-shadow: 0 0 0 3px rgba(45,122,18,0.15) !important;
753
  }
754
 
 
755
  #login_wrapper .scan-btn {
756
- border-radius: 999px !important; padding: 12px 24px !important; font-size: 14.5px !important;
757
- background: #2d7a12 !important; color: #fff !important; font-weight: 600 !important; border: none !important;
758
- height: 50px !important; margin-top: 20px !important; width: 100% !important; box-shadow: 0 10px 20px rgba(45,122,18,0.2) !important;
759
- transition: all 0.2s ease !important; letter-spacing: 0.02em !important; cursor: pointer;
 
 
760
  }
761
- #login_wrapper .scan-btn:hover { background: #236a0e !important; transform: translateY(-2px); box-shadow: 0 14px 25px rgba(45,122,18,0.3) !important; }
762
  #login_wrapper .scan-btn:active { transform: translateY(0); }
763
 
 
 
 
 
 
 
 
 
764
  .sp-error {
765
- margin-top: 15px; padding: 12px 16px; border-radius: 12px; background: rgba(231,76,60,0.1);
766
  border: 1px solid rgba(231,76,60,0.4); color: #c0392b; font-size: 13.5px; font-weight: 600;
767
  display: flex; align-items: center; gap: 10px;
768
  }
@@ -840,17 +917,24 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
840
  with gr.Row(visible=True, elem_id="login_wrapper") as login_panel:
841
  with gr.Column(elem_id="login_content_col"):
842
  gr.HTML("""
843
- <span class="badge">NỀN TẢNG CHẨN ĐOÁN THỰC VẬT</span>
844
- <h1>Không có gì<br>đứng yên trong<br><em>một hệ sinh thái</em></h1>
845
- <p class="sub">Mỗi chiếc lá là một quỹ đạo riêng. Hệ thống quét bề mặt mô lá bằng thị giác máy tính, khoanh vùng ổ bệnh theo thời gian thực và kê đơn điều trị ngay trên màn hình.</p>
 
 
 
 
 
 
846
  """)
847
- username_input = gr.Textbox(label="Tên đăng nhập", placeholder="Nhập tài khoản (admin / user)", max_lines=1, autofocus=True)
848
- password_input = gr.Textbox(label="Mật khẩu", type="password", placeholder="Nhập mật khẩu (123 / 456)", max_lines=1)
849
  error_output = gr.HTML("")
850
- btn_login = gr.Button("Bắt đầu chẩn đoán", variant="primary", elem_classes="scan-btn")
851
  gr.HTML("""
852
- <div style="margin-top: 20px; font-size: 12.5px; color: rgba(30,60,15,0.8); text-align: center;">
853
- Tài khoản thử nghiệm — Chuyên gia: <strong>admin / 123</strong> | Nhà nông: <strong>user / 456</strong>
 
854
  </div>
855
  """)
856
 
 
357
 
358
  # --- MÃ JS ANIMATION CHIẾC LÁ ---
359
  LEAF_HERO_HEAD = r"""
360
+ <link rel="preconnect" href="https://fonts.googleapis.com">
361
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
362
+ <link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
363
  <script>
364
  (function () {
365
  "use strict";
 
406
  leaves: LEAF_CASES, cycleSeconds: 16, trailCycles: 2.6, compress: 0.42,
407
  maxTurns: 3, planeSpread: 1, eccentricity: 0.25, alignToCourse: 1,
408
  driftSpeed: 1.5, driftDir: [272, 53], viewRadius: 3.1, tilt: 45, spin: 252, roll: 13.5,
409
+ lead: 0.12, focus: [0.74, 0.42], scrim: "left", scrimStrength: 0.90,
410
+ moteCount: 400, glow: 1, showCoreBeam: true, interactive: true, crossColor: "#2d7a12",
411
+ pulseColor: "#10b981", rayColor: "#8fd45a"
412
  };
413
+ const PULSE_RGB = parseRGB(C.pulseColor), RAY_RGB = parseRGB(C.rayColor);
414
+ const reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
415
 
416
  function applyResponsive() {
417
+ const w = window.innerWidth, narrow = w <= 767;
418
+ if (narrow) { C.focus = [0.5, 0.62]; }
419
+ else {
420
+ // đặt chữ thập vào giữa khoảng trống bên phải khối đăng nhập (khối ~13vw + 27rem)
421
+ const panelRight = 0.13 * w + Math.min(432, 0.81 * w);
422
+ const fx = ((panelRight + w) / 2) / w;
423
+ C.focus = [Math.min(0.82, Math.max(0.62, fx)), 0.5];
424
+ }
425
  C.scrim = narrow ? "top" : "left";
426
+ C.scrimStrength = narrow ? 0.90 : 0.90;
427
+ C.viewRadius = narrow ? 2.4 : 3.1;
428
  C.lead = narrow ? 0.05 : 0.12;
429
+ C.glow = narrow ? 0.8 : 1;
430
  }
431
  applyResponsive();
432
 
433
+ let width=0, height=0, dpr=1, years=0, lastFrame=0, clock=0, pxPerAU=1, cx=0, cy=0, camDist=1;
434
  const RIGHT={x:1,y:0,z:0}, UP={x:0,y:1,z:0}, FWD={x:0,y:0,z:1};
435
 
436
  function setCamera(yaw,pitch,roll) {
 
551
  pointerX = (ev.clientX / window.innerWidth - 0.5) * 2; pointerY = (ev.clientY / window.innerHeight - 0.5) * 2;
552
  });
553
 
554
+ // Nhịp tim lub-dub (0..1)
555
+ function heartEnv(clk) {
556
+ if (reduceMotion) return 0.15;
557
+ const T = 1.05, p = (clk % T) / T, g = (x, mu, s) => Math.exp(-((x - mu) * (x - mu)) / (2 * s * s));
558
+ return Math.min(1, g(p, 0.07, 0.045) + 0.58 * g(p, 0.27, 0.05));
559
+ }
560
+ function crossBaseR() { return Math.max(30, Math.min(width, height) * 0.066); }
561
+
562
+ // Tia sáng xoay quanh chữ thập
563
+ function drawRays(clk, env) {
564
+ const baseR = crossBaseR(), [r, g, b] = RAY_RGB;
565
+ ctx.save(); ctx.globalCompositeOperation = "lighter"; ctx.translate(cx, cy); ctx.rotate(reduceMotion ? 0 : clk * 0.12);
566
+ const n = 16, inner = baseR * 1.1;
567
+ for (let i = 0; i < n; i++) {
568
+ const ang = (i / n) * TAU, long = (i % 2 === 0), outer = baseR * (long ? 3.9 : 2.5), w = long ? 0.022 : 0.013, a = (long ? 0.11 : 0.07) + env * 0.06;
569
+ const ci = Math.cos(ang), si = Math.sin(ang), cwp = Math.cos(ang - w), swp = Math.sin(ang - w), cwn = Math.cos(ang + w), swn = Math.sin(ang + w);
570
+ const grad = ctx.createLinearGradient(ci * inner, si * inner, ci * outer, si * outer);
571
+ grad.addColorStop(0, `rgba(${r},${g},${b},${a})`); grad.addColorStop(1, `rgba(${r},${g},${b},0)`);
572
+ ctx.fillStyle = grad; ctx.beginPath();
573
+ ctx.moveTo(cwp * inner, swp * inner); ctx.lineTo(cwp * outer, swp * outer); ctx.lineTo(cwn * outer, swn * outer); ctx.lineTo(cwn * inner, swn * inner); ctx.closePath(); ctx.fill();
574
+ }
575
+ ctx.restore();
576
+ }
577
+
578
+ // Nhịp tim: hào quang + vòng lan tỏa (xanh ngọc)
579
+ function drawHeartbeat(clk, env) {
580
+ const baseR = crossBaseR(), [r, g, b] = PULSE_RGB;
581
+ ctx.save(); ctx.globalCompositeOperation = "lighter";
582
+ const glowR = baseR * (1.5 + env * 1.4), grad = ctx.createRadialGradient(cx, cy, baseR * 0.5, cx, cy, glowR);
583
+ grad.addColorStop(0, `rgba(${r},${g},${b},0)`); grad.addColorStop(0.62, `rgba(${r},${g},${b},${(0.30 * env).toFixed(3)})`); grad.addColorStop(1, `rgba(${r},${g},${b},0)`);
584
+ ctx.fillStyle = grad; ctx.beginPath(); ctx.arc(cx, cy, glowR, 0, TAU); ctx.fill();
585
+ if (!reduceMotion) {
586
+ const T = 1.05, p = (clk % T) / T;
587
+ [[0.07, 1], [0.27, 0.7]].forEach(function (mw) {
588
+ const mu = mw[0], w = mw[1]; let age = p - mu; if (age < 0) age += 1;
589
+ if (age < 0.55) {
590
+ const prog = age / 0.55, R = baseR * (1.0 + prog * 2.4), alpha = (1 - prog) * 0.35 * w;
591
+ ctx.strokeStyle = `rgba(${r},${g},${b},${alpha.toFixed(3)})`; ctx.lineWidth = (1 - prog) * 2.6 + 0.5;
592
+ ctx.beginPath(); ctx.arc(cx, cy, R, 0, TAU); ctx.stroke();
593
+ }
594
+ });
595
+ }
596
+ ctx.restore();
597
+ }
598
+
599
+ function drawCross(k, env) {
600
+ const [r, g, b] = parseRGB(C.crossColor), scale = 1 + env * 0.06, baseR = crossBaseR() * scale;
601
  const haze = ctx.createRadialGradient(cx, cy, 0, cx, cy, baseR * 4);
602
  haze.addColorStop(0, `rgba(${r},${g},${b},${0.12 * k})`); haze.addColorStop(0.4, `rgba(${r},${g},${b},${0.04 * k})`); haze.addColorStop(1, `rgba(${r},${g},${b},0)`);
603
  ctx.fillStyle = haze; ctx.beginPath(); ctx.arc(cx, cy, baseR * 4, 0, TAU); ctx.fill();
 
604
  const mid = ctx.createRadialGradient(cx, cy, 0, cx, cy, baseR * 2);
605
+ mid.addColorStop(0, `rgba(${r},${g},${b},${0.25 * k})`); mid.addColorStop(0.5, `rgba(${r},${g},${b},${0.08 * k})`); mid.addColorStop(1, `rgba(${r},${g},${b},0)`);
606
+ ctx.fillStyle = mid; ctx.beginPath(); ctx.arc(cx, cy, baseR * 2, 0, TAU); ctx.fill();
 
 
 
 
 
 
 
607
  const badgeR = baseR * 0.95, badge = ctx.createRadialGradient(cx, cy - badgeR * 0.15, badgeR * 0.2, cx, cy, badgeR);
608
  badge.addColorStop(0, "#8fcb5e"); badge.addColorStop(1, "#3c8b22");
609
  ctx.fillStyle = badge; ctx.beginPath(); ctx.arc(cx, cy, badgeR, 0, TAU); ctx.fill();
610
+ const [pr, pg, pb] = PULSE_RGB;
611
+ ctx.strokeStyle = `rgba(${pr},${pg},${pb},${(0.35 + env * 0.5).toFixed(3)})`; ctx.lineWidth = 2 + env * 1.5;
612
+ ctx.beginPath(); ctx.arc(cx, cy, badgeR + 3, 0, TAU); ctx.stroke();
613
  const armLen = badgeR * 0.6, armW = badgeR * 0.22, rad = armW * 0.45;
614
  ctx.fillStyle = "#fff";
615
  ctx.beginPath(); ctx.roundRect(cx - armW, cy - armLen, armW * 2, armLen * 2, rad); ctx.fill();
 
626
  }
627
 
628
  function render(t) {
629
+ const k = C.glow, env = heartEnv(clock); layout(); syncElements();
630
  camX += (pointerX - camX) * 0.04; camY += (pointerY - camY) * 0.04;
631
  setCamera(C.spin + camX * 7, C.tilt + camY * 5, C.roll);
632
  dist = C.driftSpeed * t; cx = width * C.focus[0]; cy = height * C.focus[1];
 
649
  });
650
  ctx.setLineDash([]);
651
  const dRef = D_NEAR * 3.3, left = -width * 0.12, right = width * 1.12, top = -height * 0.12, bottom = height * 1.12;
652
+ for (let s = 0; s < starN; s++) {
653
  project(sx[s] - DIR.x * dist, sy[s] - DIR.y * dist, sz[s] - DIR.z * dist);
654
  if (!P.ok || P.depth > D_FAR * 1.25) { seedStar(s); continue; }
655
  if (P.x < left || P.x > right || P.y < top || P.y > bottom) { seedStar(s, undefined, P.x < left ? 1 : P.x > right ? 0 : P.y < top ? 3 : 2); continue; }
656
  if (P.depth < D_NEAR * 0.75) continue;
657
  const near = Math.min(1, (P.depth - D_NEAR * 0.75) / (D_NEAR * 0.6));
658
  const far = 1 - Math.max(0, (P.depth - D_FAR * 0.78) / (D_FAR * 0.32));
659
+ let a = (0.4 + sMag[s] * 1.5) * Math.pow(dRef / P.depth, 0.8) * near * far;
660
  if (a <= 0.01) continue;
661
+ a *= 0.85 + 0.15 * Math.sin(t * 7 + sPhase[s]);
662
+ const col = sTint[s] === 1 ? "211,84,0" : sTint[s] === 2 ? "20,90,20" : "39,174,96";
663
+ const size = Math.min(5.5, 1.5 + sMag[s] * 4.0 * Math.pow(dRef / P.depth, 0.5));
664
+ ctx.globalAlpha = Math.min(0.95, a);
 
 
 
 
 
 
665
  ctx.fillStyle = `rgb(${col})`;
666
  if (size < 1.2) ctx.fillRect(P.x, P.y, size, size);
667
  else { ctx.beginPath(); ctx.arc(P.x, P.y, size * 0.5, 0, TAU); ctx.fill(); }
 
707
 
708
  let idx = 0;
709
  while (idx < shots.length && shots[idx].depth > camDist) drawShot(shots[idx], idx++);
710
+ drawRays(clock, env);
711
+ drawHeartbeat(clock, env);
712
+ drawCross(k, env);
713
  while (idx < shots.length) drawShot(shots[idx], idx++);
714
  drawBorderLeaves(t);
715
 
 
727
  if (!active || document.hidden) { lastFrame = now; return; }
728
  const dt = lastFrame ? Math.min(0.05, (now - lastFrame) / 1000) : 0;
729
  lastFrame = now;
730
+ clock = now / 1000;
731
  years += dt / Math.max(0.1, C.cycleSeconds);
732
  render(years);
733
  }
 
755
  """
756
 
757
  custom_css = """
758
+ /* ===================== LEAF HERO LOGIN (v4) ===================== */
759
  #leaf-bg {
760
  position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0;
761
  opacity: 0; pointer-events: none; transition: opacity 0.6s ease;
762
  }
763
  body.leaf-on #leaf-bg { opacity: 1; }
764
+ body.leaf-on { background: #e8f5d6 !important; margin: 0; padding: 0;
765
+ font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
766
+ body.leaf-on .gradio-container { background: transparent !important; font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important; }
767
+ #login_wrapper h1, #login_wrapper p, #login_wrapper label, #login_wrapper label span, #login_wrapper input, #login_wrapper textarea, #login_wrapper button { font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important; }
768
 
769
  #login_wrapper {
770
  position: relative; z-index: 2; min-height: 100vh;
771
  display: flex !important; align-items: center !important;
772
+ padding: 0 6vw 0 13vw !important; box-sizing: border-box;
773
  }
774
  #login_wrapper.hide { display: none !important; }
775
 
776
+ /* Bỏ hẳn panel kính — chữ & khối nằm trực tiếp trên nền (như leaf v4) */
777
  #login_content_col {
778
+ max-width: 27rem !important; width: 100% !important; margin: 0 !important;
779
+ background: transparent !important; padding: 0 !important;
780
+ border: none !important; box-shadow: none !important;
781
+ -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
 
782
  }
783
  @media (max-width: 767px) {
784
+ #login_wrapper { padding: 12vh 1.5rem 0 !important; align-items: flex-start !important; }
785
+ #login_content_col { max-width: 100% !important; }
786
  }
787
 
788
+ /* Brand head: badge (nhịp tim) + tên trung tâm nổi bật */
789
+ .lv4-head { display: flex; align-items: flex-start; gap: .85rem; margin-bottom: .3rem; }
790
+ .lv4-badge { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 14px; margin-top: 3px;
791
+ display: grid; place-items: center;
792
+ background: radial-gradient(circle at 35% 30%, #8fcb5e, #2f8b1c);
793
+ box-shadow: 0 8px 20px -8px rgba(45,122,18,0.7), inset 0 1px 0 rgba(255,255,255,0.5); }
794
+ .lv4-badge svg { width: 23px; height: 23px; }
795
+ .lv4-heart { transform-origin: center; animation: lv4-beat 1.05s ease-in-out infinite; }
796
+ .lv4-copy { min-width: 0; }
797
+ .lv4-title { margin: 0; font-weight: 800; line-height: 1.12; letter-spacing: -.02em;
798
+ font-size: clamp(1.5rem, 2.6vw, 2.1rem); color: #16281a; }
799
+ .lv4-accent { background: linear-gradient(120deg, #34d399, #059669 55%, #2d7a12);
800
+ -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
801
+ .lv4-sub { margin: .6rem 0 .2rem; font-size: .92rem; color: #3d5233; }
802
+ @keyframes lv4-beat { 0%,100%{transform:scale(1);} 6%{transform:scale(1.22);} 12%{transform:scale(1);} 26%{transform:scale(1.13);} 34%{transform:scale(1);} }
803
+ @media (prefers-reduced-motion: reduce){ .lv4-heart{ animation: none; } }
804
+
805
+ /* Ô nhập kiểu leaf v4 */
806
  #login_wrapper .gr-form, #login_wrapper .block, #login_wrapper .form { background: transparent !important; border: none !important; box-shadow: none !important; }
807
+ #login_wrapper label span, #login_wrapper .gr-box label { color: #3d5233 !important; font-size: 13px !important; font-weight: 600 !important; letter-spacing: .01em !important; }
808
  #login_wrapper input[type="text"], #login_wrapper input[type="password"] {
809
+ background: rgba(255,255,255,0.55) !important; border: 1px solid rgba(90,110,70,0.32) !important;
810
+ border-radius: 14px !important; color: #16281a !important; font-size: 15px !important; min-height: 50px !important;
811
+ padding: 0 16px !important; -webkit-backdrop-filter: blur(6px) !important; backdrop-filter: blur(6px) !important;
812
+ transition: all 0.2s ease !important;
813
  }
814
+ #login_wrapper input::placeholder { color: #5f7255 !important; }
815
+ #login_wrapper input:hover { border-color: rgba(16,185,129,0.45) !important; }
816
  #login_wrapper input:focus, #login_wrapper input:focus-visible {
817
+ border-color: #10b981 !important; background: rgba(255,255,255,0.9) !important; outline: none !important;
818
+ box-shadow: 0 0 0 4px rgba(16,185,129,0.35) !important;
819
  }
820
 
821
+ /* Nút lớn KÍCH HOẠT PHIÊN XÉT NGHIỆM */
822
  #login_wrapper .scan-btn {
823
+ border-radius: 14px !important; min-height: 56px !important; margin-top: 8px !important; width: 100% !important;
824
+ font-size: 15px !important; font-weight: 800 !important; letter-spacing: .08em !important; text-transform: uppercase !important;
825
+ color: #fff !important; border: none !important; cursor: pointer;
826
+ background: linear-gradient(135deg, #10b981, #047857) !important;
827
+ box-shadow: 0 16px 34px -14px rgba(5,150,105,0.75), inset 0 1px 0 rgba(255,255,255,0.25) !important;
828
+ transition: all 0.2s ease !important;
829
  }
830
+ #login_wrapper .scan-btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 20px 40px -14px rgba(5,150,105,0.85) !important; }
831
  #login_wrapper .scan-btn:active { transform: translateY(0); }
832
 
833
+ /* Tài khoản thử nghiệm */
834
+ .lv4-demo { margin-top: 1.4rem; font-size: .8rem; color: #5f7255; }
835
+ .lv4-demo-title { display: block; margin-bottom: .5rem; font-weight: 600; color: #3d5233; }
836
+ .lv4-demo-row { display: flex; align-items: center; gap: .5rem; }
837
+ .lv4-chip { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace !important; font-size: .78rem; font-weight: 600;
838
+ color: #047857; background: rgba(16,185,129,0.14); border: 1px solid rgba(16,185,129,0.28);
839
+ padding: .22rem .6rem; border-radius: .5rem; }
840
+
841
  .sp-error {
842
+ margin-top: 12px; padding: 12px 16px; border-radius: 12px; background: rgba(231,76,60,0.1);
843
  border: 1px solid rgba(231,76,60,0.4); color: #c0392b; font-size: 13.5px; font-weight: 600;
844
  display: flex; align-items: center; gap: 10px;
845
  }
 
917
  with gr.Row(visible=True, elem_id="login_wrapper") as login_panel:
918
  with gr.Column(elem_id="login_content_col"):
919
  gr.HTML("""
920
+ <div class="lv4-head">
921
+ <div class="lv4-badge" aria-hidden="true">
922
+ <svg class="lv4-heart" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke="#fff" stroke-width="3.4" stroke-linecap="round"/></svg>
923
+ </div>
924
+ <div class="lv4-copy">
925
+ <h1 class="lv4-title">Trung tâm Chẩn đoán &amp; Điều trị Bệnh <span class="lv4-accent">Cây trồng</span> Công nghệ cao</h1>
926
+ <p class="lv4-sub">Xác thực để mở phiên xét nghiệm mô lá.</p>
927
+ </div>
928
+ </div>
929
  """)
930
+ username_input = gr.Textbox(label="Tên đăng nhập", placeholder="Nhập tên đăng nhập", max_lines=1, autofocus=True)
931
+ password_input = gr.Textbox(label="Mật khẩu", type="password", placeholder="••••••••", max_lines=1)
932
  error_output = gr.HTML("")
933
+ btn_login = gr.Button("Kích hoạt phiên xét nghiệm", variant="primary", elem_classes="scan-btn")
934
  gr.HTML("""
935
+ <div class="lv4-demo">
936
+ <span class="lv4-demo-title">Tài khoản thử nghiệm</span>
937
+ <div class="lv4-demo-row"><span>Nhà nông:</span> <span class="lv4-chip">user / 456</span></div>
938
  </div>
939
  """)
940