ThreeT2105 commited on
Commit
bca011e
·
verified ·
1 Parent(s): 3bc6f6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -135
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import os
2
  import cv2
3
  import gradio as gr
@@ -1094,7 +1097,7 @@ LEAF_HERO_HEAD = r"""
1094
  <script>
1095
  (function () {
1096
  "use strict";
1097
- /* ============ CHỌN CAMERA TRƯỚC / SAU KHI CHỤP ẢNH LÁ ============
1098
  Điện thoại thường có 2 camera. Trình duyệt hay mở camera TRƯỚC, trong khi chụp lá
1099
  thì phải dùng camera SAU (ống kính chính, nét hơn). Khối này:
1100
  1) Vá getUserMedia để mọi lần xin camera đều kèm facingMode theo lựa chọn hiện tại.
@@ -1405,7 +1408,7 @@ custom_css = """
1405
  background: linear-gradient(180deg, #eff5f3 0%, #e1ebe7 100%) !important;
1406
  font-family: 'Inter', system-ui, sans-serif !important;
1407
  }
1408
- #login_wrapper { padding: 0 !important; } /* cũ: display:flex !important gây kẹt ẩn/hiện — đã bỏ */
1409
  .login-card {
1410
  background: #ffffff !important; border-radius: 24px !important; padding: 45px 40px !important;
1411
  box-shadow: 0 20px 45px rgba(0, 60, 40, 0.06) !important; border: 1px solid rgba(0, 129, 112, 0.1) !important;
@@ -1679,9 +1682,7 @@ body.leaf-on footer { display: none !important; }
1679
  }
1680
  /* =================== END LEAF HERO LOGIN =================== */
1681
 
1682
- /* ============ ĐỒNG BỘ MÀN LÀM VIỆC VỚI MÀN ĐĂNG NHẬP (leaf v4) ============
1683
- Khối này đặt CUỐI custom_css để ghi đè các rule cũ phía trên mà không phải xoá
1684
- chúng đi — dễ đối chiếu và lùi lại nếu cần. Không đụng tới #login_wrapper. */
1685
  :root {
1686
  --lf-bg1:#eef8e1; --lf-bg2:#e3f2d0;
1687
  --lf-ink:#16281a; --lf-ink2:#3d5233; --lf-muted:#5f7255;
@@ -1696,9 +1697,6 @@ body.leaf-on footer { display: none !important; }
1696
 
1697
  /* --- Nền: cùng tông xanh lá với màn đăng nhập + lá TĨNH rất mờ (không animation) --- */
1698
  .gradio-container {
1699
- /* Dung LONGHAND, khong dung shorthand + var(): neu var() thay the ra gia tri khong
1700
- hop le thi CA shorthand background bi vut ve initial (nen thanh trong suot).
1701
- Tach longhand ra thi mau nen van con du anh la co loi. */
1702
  background-color: #eef8e1 !important;
1703
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='820' height='820' viewBox='0 0 820 820'><g fill='%232f8b1c' fill-opacity='0.055'><g transform='translate(70,60) rotate(18)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(300,150) rotate(-35) scale(1.3)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(620,80) rotate(52)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(150,380) rotate(-12) scale(0.85)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(470,430) rotate(70) scale(1.15)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(740,330) rotate(-48)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(60,640) rotate(40) scale(1.25)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(360,690) rotate(-62)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(660,620) rotate(15) scale(0.9)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g></g></svg>"), linear-gradient(180deg, #eef8e1 0%, #e3f2d0 100%) !important;
1704
  background-attachment: fixed, fixed !important;
@@ -1742,11 +1740,6 @@ body.leaf-on footer { display: none !important; }
1742
  border: 1px solid var(--lf-bd) !important;
1743
  border-radius: var(--lf-r) !important;
1744
  box-shadow: 0 10px 28px -22px rgba(6,95,70,0.5) !important;
1745
- /* KHONG dung backdrop-filter o day. Gradio ve danh sach cua Dropdown bang
1746
- position:fixed va dat NAM TRONG component; ma backdrop-filter lai tao
1747
- "containing block" cho con position:fixed -> danh sach bi neo vao the nay
1748
- roi bi overflow:hidden cua no cat mat, khien khong chon duoc loai cay.
1749
- Bu lai do trong bang cach tang do duc cua --lf-card. */
1750
  }
1751
 
1752
  /* Gradio lồng .gr-group trong .gr-group. Nếu cả hai cùng nhận nền kính + viền thì
@@ -1944,7 +1937,7 @@ body.leaf-on footer { display: none !important; }
1944
  }
1945
  /* ============ HẾT PHẦN ĐỒNG BỘ MÀN LÀM VIỆC ============ */
1946
 
1947
- /* ============ TÙY CHỈNH THEO YÊU CẦU MỚI NHẤT (chỉ thêm, không xoá/sửa gì ở trên) ============
1948
  1. Nút "ĐĂNG XUẤT HỆ THỐNG" -> màu đỏ nhạt
1949
  2. Khung "HỘI ĐỒNG TƯ VẤN THUỐC BẢO VỆ THỰC VẬT (CHATBOT AI)" -> nền xanh dương nhạt nhạt
1950
  3. Nút "Xem Lại Lịch Sử Bệnh Án" khi hover -> đổi màu giống nút "GỬI AI" (scan-btn, xanh emerald)
@@ -1986,25 +1979,6 @@ body.leaf-on footer { display: none !important; }
1986
  }
1987
  /* ============ HẾT PHẦN TÙY CHỈNH MỚI ============ */
1988
 
1989
- /* ============ (KHỐI CŨ ĐÃ GỠ) SỬA LỖI NÚT PHÓNG TO ẢNH ============
1990
- Khối CSS phóng to ảnh cũ từng nằm ở đây đã được gỡ và viết lại cho đúng.
1991
- Bản mới nằm ở CUỐI custom_css, mục "SỬA LẠI NÚT PHÓNG TO ẢNH (FULLSCREEN) — BẢN 2".
1992
- Lý do phải gỡ chứ không sửa tại chỗ: bản cũ đặt TRƯỚC mấy rule chiều cao ăn theo class
1993
- .lf-co-anh / .lf-trong ở cuối file, mà mấy rule đó ưu tiên cao hơn hẳn nên luôn thắng —
1994
- bản cũ có để ở đây cũng không bao giờ có tác dụng. */
1995
-
1996
- /* ============ TÙY CHỈNH MÀU NỀN KHUNG TIÊU ĐỀ (chỉ thêm mới, không đụng gì ở trên) ============
1997
- Khung "TRUNG TÂM CHẨN ĐOÁN & ĐIỀU TRỊ BỆNH CÂY TRỒNG CÔNG NGHỆ CAO" (ở màn làm việc) và
1998
- khung "KHO LƯU TRỮ HỒ SƠ & LỊCH SỬ HỆ THỐNG" (ở màn lịch sử) đều dùng chung class
1999
- .hospital-header. Đổi nền sang xanh emerald nhạt hơn một chút so với các khung trắng
2000
- khác (.gr-group, #chatbot_col) để nổi bật, nhưng vẫn cùng tông xanh emerald chủ đạo của
2001
- toàn giao diện — không dùng màu quá đậm. Đặt sau cùng nên thắng rule nền cũ ở trên. */
2002
- .hospital-header {
2003
- background: linear-gradient(120deg, rgba(167,243,208,0.65), rgba(110,231,183,0.45)) !important;
2004
- border: 1px solid rgba(16,185,129,0.35) !important;
2005
- }
2006
- /* ============ HẾT PHẦN TÙY CHỈNH MÀU NỀN KHUNG TIÊU ĐỀ ============ */
2007
-
2008
  /* ============ CẬP NHẬT MÀU NỀN KHUNG TIÊU ĐỀ THEO YÊU CẦU MỚI NHẤT
2009
  (chỉ thêm mới, không đụng/xoá bất kỳ rule nào ở trên) ============
2010
  Yêu cầu: khung "TRUNG TÂM CHẨN ĐOÁN & ĐIỀU TRỊ BỆNH CÂY TRỒNG..." và khung
@@ -2097,10 +2071,7 @@ body.leaf-on footer { display: none !important; }
2097
  /* ============ HẾT PHẦN HIỆU ỨNG LÁ BAY BAY ============ */
2098
 
2099
  /* ============ PHẦN CHỤP ẢNH: NÚT NGUỒN CÓ CHỮ + BỘ CHỌN CAMERA TRƯỚC/SAU ============
2100
- Vấn đề cũ: Gradio để 3 nút nguồn ảnh là 3 icon 22x22 không nhãn, xám nhạt, nằm nép
2101
- dưới đáy khung — bà con không nhận ra chỗ nào để bấm chụp. Chuẩn vùng chạm tối thiểu
2102
- là 44x44 và nút chỉ có icon thì phải có nhãn.
2103
- Cách sửa: phóng to thành 3 nút có chữ tiếng Việt, nút "Chụp ảnh" làm nút chính. */
2104
  .lf-img { position: relative !important; }
2105
 
2106
  .lf-img .source-selection {
@@ -2126,16 +2097,11 @@ body.leaf-on footer { display: none !important; }
2126
  .lf-img .source-selection button svg { width: 16px !important; height: 16px !important; flex: 0 0 16px !important; }
2127
  .lf-img .source-selection button:hover { background: #fff !important; border-color: var(--lf-em) !important; }
2128
  .lf-img .source-selection button:focus-visible { outline: 3px solid rgba(16,185,129,.45) !important; outline-offset: 2px !important; }
2129
- /* Nhãn tiếng Việt. Chọn theo THỨ TỰ (tải / chụp / dán) chứ không theo aria-label,
2130
- vì Gradio dịch aria-label theo ngôn ngữ trình duyệt — máy đang hiển thị tiếng Pháp. */
2131
  .lf-img .source-selection button:nth-child(1)::after { content: "Tải ảnh"; }
2132
  .lf-img .source-selection button:nth-child(2)::after { content: "Chụp ảnh"; }
2133
  .lf-img .source-selection button:nth-child(3)::after { content: "Dán ảnh"; }
2134
- /* CHẾ ĐỘ ĐANG CHỌN mới được tô xanh.
2135
- Trước đây tôi tô cứng nút thứ 2 ("Chụp ảnh") để làm nút chính, nhưng trong một nhóm
2136
- 3 lựa chọn thì màu xanh bị hiểu là "đang chọn" — hai ý nghĩa đá nhau, nên nút xanh
2137
- lại không phải nút đang dùng. Gradio đánh dấu chế độ hiện hành bằng class .selected,
2138
- vậy bám đúng vào đó: chọn cái nào thì cái đó xanh, cái còn lại để trắng. */
2139
  .lf-img .source-selection button.selected {
2140
  background: linear-gradient(135deg, var(--lf-em), var(--lf-em-d)) !important;
2141
  border-color: transparent !important; color: #fff !important;
@@ -2146,7 +2112,7 @@ body.leaf-on footer { display: none !important; }
2146
  filter: brightness(1.06) !important; border-color: transparent !important;
2147
  }
2148
 
2149
- /* Dải chọn camera: nổi trên khung xem trước, đặt dưới nhãn khung để không đè chữ */
2150
  .lf-cam-switch {
2151
  position: absolute !important; left: 10px !important; right: 10px !important; top: 44px !important;
2152
  z-index: 26 !important;
@@ -2186,32 +2152,44 @@ body.leaf-on footer { display: none !important; }
2186
  .lf-cam-opt:focus-visible { outline: 3px solid #a7f3d0 !important; outline-offset: 2px !important; }
2187
  .lf-cam-switch.is-busy .lf-cam-opt { opacity: .55 !important; pointer-events: none !important; }
2188
 
 
2189
  @media (max-width: 767px) {
2190
- /* Trên điện thoại giữ 44px — đây là ngưỡng tối thiểu để ngón tay bấm trúng,
2191
- nên chỉ thu được ~8% chứ không thu đủ 10% như bản desktop. */
2192
- .lf-img .source-selection button { min-height: 44px !important; font-size: 11.5px !important; }
2193
- .lf-cam-opt { min-height: 48px !important; font-size: 14px !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2194
  }
 
2195
  @media (prefers-reduced-motion: reduce) {
2196
  .lf-img .source-selection button, .lf-cam-opt { transition: none !important; }
2197
  }
2198
  /* ============ HẾT PHẦN CHỤP ẢNH / CHỌN CAMERA ============ */
2199
 
2200
- /* ============ SỬA LỖI TRANG KHÔNG CUỘN XUỐNG ĐƯỢC SAU KHI HỎI AI
2201
- (chỉ thêm mới, không đụng/xoá bất kỳ rule nào ở trên) ============
2202
- Phần giải thích đầy đủ nằm ở khối <script> cuối LEAF_HERO_HEAD. Tóm tắt: các rule
2203
- co giãn phía trên dò trạng thái bằng :has(), mà trình duyệt không tính lại :has()
2204
- khi Gradio chèn thẻ mới, làm khung kẹt sai chiều cao và trang cuộn không tới đáy.
2205
- Mấy rule dưới đây ăn theo class thường do JS gắn (đường tính lại luôn đúng), đặt
2206
- SAU CÙNG và độ ưu tiên cao hơn bản :has() nên luôn thắng, kể cả lúc bản :has() kẹt. */
2207
- /* Vì sao lặp tên class 3 lần? Gradio tự chèn tiền tố
2208
- ".gradio-container.gradio-container-6-24-0 .contain " vào TRƯỚC mọi bộ chọn trong
2209
- custom_css, làm mấy rule :has() ở trên được cộng thêm 3 hạng ưu tiên. Nếu ở đây tự
2210
- thêm tiền tố kiểu "body .gradio-container" thì bản có tiền tố của nó lại đòi thẻ
2211
- <body> nằm BÊN TRONG .contain — chuyện không bao giờ xảy ra — nên rule coi như mất
2212
- tác dụng và bản :has() (đang kẹt) vẫn thắng. Đã đo và dính đúng bẫy này.
2213
- Lặp class là cách tăng ưu tiên duy nhất sống sót qua cả hai phiên bản có/không có
2214
- tiền tố, nên chắc chắn thắng bản :has() trong mọi trường hợp. */
2215
  .lf-chat.lf-it-tin.lf-it-tin.lf-it-tin { height: 340px !important; }
2216
  .lf-chat.lf-nhieu-tin.lf-nhieu-tin.lf-nhieu-tin { height: 560px !important; }
2217
  .lf-img.lf-trong.lf-trong.lf-trong { height: 230px !important; }
@@ -2221,53 +2199,16 @@ body.leaf-on footer { display: none !important; }
2221
  .lf-img.lf-co-anh.lf-co-anh.lf-co-anh { height: 330px !important; }
2222
  .lf-chat.lf-nhieu-tin.lf-nhieu-tin.lf-nhieu-tin { height: 460px !important; }
2223
  }
2224
- /* Khoá cuộn của màn đăng nhập: bỏ hẳn :has() khỏi đường này. Rule html:has(body.leaf-on)
2225
- ở trên khoá cứng trang — nếu nó kẹt lại sau khi đã rời màn đăng nhập thì bà con không
2226
- cuộn nổi trang nữa. Thay bằng class gắn thẳng lên thẻ <html>, ưu tiên cao hơn. */
2227
  html:root.lf-khoa-cuon.lf-khoa-cuon { overflow: hidden !important; }
2228
  html:root:not(.lf-khoa-cuon):not(.lf-khoa-cuon) { overflow-y: auto !important; }
2229
- /* NGUYÊN NHÂN GỐC — HIỆU ỨNG CO GIÃN BỊ TREO.
2230
- Đo được tận nơi bằng getAnimations(): sau khi AI trả lời, khung chat có một hiệu ứng
2231
- chuyển động chiều cao ở trạng thái "running" nhưng currentTime ĐỨNG YÊN Ở 0 — nó không
2232
- bao giờ chạy tiếp. Hậu quả: chiều cao bị ghim vĩnh viễn ở giá trị CŨ, kéo theo chiều
2233
- cao cả trang cũng đứng yên, nên kéo thanh cuộn tới đáy vẫn thiếu một khúc và khung
2234
- "Ảnh mẫu lá bệnh do nhà nông gửi lên" ở dưới cùng bị cắt mất.
2235
- Bấm sang màn lịch sử rồi quay lại thì Gradio dựng lại thẻ, hiệu ứng treo bị xoá theo
2236
- nên trang cuộn lại bình thường — đúng y như bà con mô tả.
2237
- Đã thử đối chứng: tắt hiệu ứng đi thì khung nhảy đúng cỡ ngay và trang cuộn tới đáy,
2238
- cả trên máy tính lẫn điện thoại.
2239
- Cái giá phải trả: mấy khung này đổi cỡ ngay lập tức thay vì giãn ra mượt mà. Đổi lại
2240
- là chắc chắn không kẹt nữa — đáng.
2241
- Lặp tên class 5 lần để thắng độ ưu tiên của rule transition gốc SAU KHI Gradio tự chèn
2242
- tiền tố ".gradio-container.gradio-container-6-24-0 .contain " vào trước nó. */
2243
  .lf-chat.lf-chat.lf-chat.lf-chat.lf-chat,
2244
  .lf-img.lf-img.lf-img.lf-img.lf-img,
2245
  .textbox_custom.textbox_custom.textbox_custom.textbox_custom.textbox_custom textarea {
2246
  transition: none !important;
2247
  }
2248
- /* ============ SỬA LẠI NÚT PHÓNG TO ẢNH (FULLSCREEN) — BẢN 2 ============
2249
- TRIỆU CHỨNG bà con báo: bấm nút phóng to ở ô "Ảnh quét tế bào bề mặt lá" (và ô
2250
- "Bản đồ nội soi vi vị trí") thì ảnh KHÔNG to ra, vẫn y nguyên cỡ cũ, mà lại có
2251
- "cái gì đó" bị phóng ra thành một dải tối chạy hết bề ngang màn hình.
2252
-
2253
- NGUYÊN NHÂN đã đo tận nơi trên trình duyệt:
2254
- Gradio 6.24 phóng to ảnh bằng cách gắn thêm class "fullscreen" vào chính ô ảnh, kèm
2255
- rule của Gradio: .fullscreen { position: fixed; top:0; left:0; width:100%; height:100% }.
2256
- Nhưng ở cuối file này đang có rule ghim chiều cao ô ảnh:
2257
- .lf-img.lf-co-anh.lf-co-anh.lf-co-anh { height: 420px !important; }
2258
- Rule đó lặp tên class 3 lần, lại được Gradio chèn thêm tiền tố
2259
- ".gradio-container.gradio-container-6-24-0 .contain " nên độ ưu tiên rất cao, và có
2260
- !important nên thắng cả animation phóng to của Gradio (animation KHÔNG đè được
2261
- !important). Kết quả đo được lúc đang phóng to: ô ảnh rộng đúng 1280px (chạy hết
2262
- bề ngang) nhưng CAO VẪN 420px — đúng cái dải tối bà con thấy; còn tấm ảnh bên trong
2263
- thì vẫn nằm gọn trong 420px đó nên trông như không to thêm chút nào.
2264
-
2265
- CÁCH SỬA: đặt ở CUỐI CÙNG một khối chỉ có hiệu lực khi ô ảnh đang mang class
2266
- "fullscreen", gỡ đúng cái ghim chiều cao đó rồi trả ô ảnh về đúng cỡ toàn màn hình,
2267
- đồng thời cho tấm ảnh nở hết khung mà vẫn giữ nguyên tỉ lệ.
2268
- Lặp tên class "fullscreen" 5 lần vì lý do y hệt mục ở trên: phải cao hơn độ ưu tiên
2269
- của .lf-img.lf-co-anh.lf-co-anh.lf-co-anh SAU KHI cả hai cùng được Gradio chèn tiền tố.
2270
- Lúc KHÔNG phóng to thì khối này không khớp gì cả, nên mọi thứ ở trên giữ nguyên. */
2271
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen {
2272
  position: fixed !important;
2273
  top: 0 !important; left: 0 !important;
@@ -2278,37 +2219,24 @@ html:root:not(.lf-khoa-cuon):not(.lf-khoa-cuon) { overflow-y: auto !important; }
2278
  border-radius: 0 !important;
2279
  z-index: 1000 !important;
2280
  overflow: hidden !important;
2281
- /* Nền tối cho dễ nhìn ảnh, giống kiểu xem ảnh phóng to quen thuộc. */
2282
  background: rgba(8,20,14,0.94) !important;
2283
  display: flex !important;
2284
  align-items: center !important;
2285
  justify-content: center !important;
2286
- /* Khối "tắt hiệu ứng co giãn" ở trên đã tắt transition rồi, ghi lại cho chắc: lúc
2287
- phóng to mà còn transition chiều cao thì dễ dính lại đúng lỗi kẹt cũ. */
2288
  transition: none !important;
2289
  }
2290
- /* Ruột ô ảnh phải nở theo, nếu không thì ô ngoài to mà ảnh vẫn kẹt trong khung con cũ. */
2291
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-container,
2292
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-frame {
2293
  width: 100% !important; height: 100% !important;
2294
  max-width: none !important; max-height: none !important;
2295
  }
2296
- /* Gradio để sẵn object-fit: scale-down cho thẻ ảnh, nghĩa là ảnh nhỏ hơn màn hình thì
2297
- GIỮ NGUYÊN cỡ gốc chứ không phóng lên — bấm "phóng to" mà ảnh y như cũ là vì vậy.
2298
- Đổi sang contain: ảnh nở hết cỡ vừa màn hình, vẫn đúng tỉ lệ, không méo. */
2299
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-frame img {
2300
  width: 100% !important; height: 100% !important;
2301
  max-width: none !important; max-height: none !important;
2302
  object-fit: contain !important;
2303
  }
2304
- /* Mấy ô ảnh CÒN LẠI (ảnh mẫu nhà nông gửi lên, ảnh trong hộp thư chuyên gia) không mang
2305
- class .lf-img nên không dính lỗi trên — Gradio tự lo được. Nhưng chúng vẫn giữ
2306
- object-fit: scale-down, tức ảnh nhỏ hơn màn hình thì bấm phóng to cũng y nguyên cỡ cũ.
2307
- Một dòng dưới đây cho mọi ô ảnh trong app phóng to giống nhau: nở hết cỡ, đúng tỉ lệ. */
2308
  .block.fullscreen .image-frame img { object-fit: contain !important; }
2309
  /* ============ HẾT PHẦN SỬA LẠI NÚT PHÓNG TO ẢNH ============ */
2310
-
2311
- /* ============ HẾT PHẦN SỬA LỖI CUỘN TRANG ============ */
2312
  """
2313
 
2314
  initial_ticket_text, initial_ticket_img = check_user_expert_status()
@@ -2338,7 +2266,6 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2338
  </div>
2339
  """)
2340
 
2341
-
2342
  with gr.Column(visible=False) as main_panel:
2343
  with gr.Row(elem_classes="hospital-header"):
2344
  with gr.Column(scale=10, elem_classes="hospital-header-center"):
@@ -2351,19 +2278,22 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2351
  """)
2352
  with gr.Column(scale=2, min_width=210):
2353
  with gr.Row():
2354
- btn_logout = gr.Button("ĐĂNG XUẤT HỆ THỐNG", elem_classes="logout-btn-style")
 
2355
  with gr.Row():
2356
  with gr.Column(scale=10):
2357
  with gr.Group(elem_classes="gr-group"):
2358
  gr.Markdown("""<p class="sec-head"><span class="sec-n">1</span><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="2" width="8" height="4" rx="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M8 11h8M8 15h5"/></svg>TIẾP NHẬN MẪU XÉT NGHIỆM</p>""")
2359
  plant_dropdown = gr.Dropdown(
2360
  choices=["Cây dâu tây", "Cây lúa", "Cây ớt", "Cây cà chua", "Cây cà phê", "Cây ngô (Bắp)", "Cây nho"],
2361
- value="Cây dâu tây", label="Lựa chọn phân khoa điều trị thực vật" )
 
2362
  with gr.Group(elem_classes="gr-group"):
2363
  image_input = gr.Image(type="numpy", label="Ảnh quét tế bào bề mặt lá", height=370, elem_classes="lf-img")
2364
  gr.HTML("<div style='padding: 0 10px 10px 10px;'>")
2365
  btn_analyze = gr.Button("TIẾN HÀNH QUÉT & CHẨN ĐOÁN LÂM SÀNG", variant="primary", elem_classes="scan-btn")
2366
- gr.HTML("</div>")
 
2367
  with gr.Column(scale=11, elem_id="prescription_col"):
2368
  with gr.Group(elem_classes="gr-group"):
2369
  gr.Markdown("""<p class="sec-head"><span class="sec-n">2</span><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7V5a2 2 0 0 1 2-2h2"/><path d="M17 3h2a2 2 0 0 1 2 2v2"/><path d="M21 17v2a2 2 0 0 1-2 2h-2"/><path d="M7 21H5a2 2 0 0 1-2-2v-2"/><circle cx="12" cy="12" r="3"/></svg>KẾT QUẢ QUÉT THỊ GIÁC HỌC SÂU (AI DETECT)</p>""")
@@ -2373,7 +2303,8 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2373
  label="Hồ sơ bệnh án điện tử xuất từ thuật toán",
2374
  lines=5,
2375
  placeholder="Hồ sơ bệnh án sơ bộ sẽ tự động xuất ra tại đây...",
2376
- elem_classes="textbox_custom" )
 
2377
 
2378
  with gr.Column(scale=12, elem_id="chatbot_col"):
2379
  with gr.Row(elem_classes="chatbot-title-container"):
@@ -2383,11 +2314,13 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2383
  value=[{"role": "assistant", "content": "🤖 Hệ thống đang đợi mẫu quét. Sau khi phân tích xong ảnh lá, tôi sẽ tự động nắm thông tin b��nh lý để kê đơn thuốc chính xác cho bà con!"}],
2384
  height=550,
2385
  label="Trò chuyện trực tiếp với Chuyên gia Bảo vệ Thực vật AI",
2386
- elem_classes=["chatbot_custom", "lf-chat"] )
 
2387
  with gr.Row(elem_id="chat_input_row"):
2388
  chat_msg = gr.Textbox(
2389
  placeholder="Hỏi chuyên gia về cách chữa trị, tên thuốc, liều lượng phun bón cho loại bệnh vừa quét...",
2390
- scale=8, max_lines=1, label="Câu hỏi của bà con" )
 
2391
  btn_send = gr.Button("GỬI AI", scale=1, variant="primary", elem_classes="scan-btn")
2392
 
2393
  with gr.Group(elem_classes="gr-group", visible=True) as user_expert_section:
@@ -2398,7 +2331,7 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2398
  expert_status_box = gr.HTML(value=initial_ticket_text)
2399
  expert_ticket_img_view = gr.Image(value=initial_ticket_img, label="Ảnh mẫu lá bệnh do nhà nông gửi lên", height=250, interactive=False)
2400
 
2401
- gr.HTML("<div class='footer-text'>Hệ thống lõi được bảo mật bởi AI Doctor Lab © 2026 | Nền tảng Phân tích Công nghệ cao Học máy Ultralytics YOLOv8 & Google Gemini AI</div>")
2402
 
2403
  with gr.Column(visible=False) as history_panel:
2404
  with gr.Row(elem_classes="hospital-header"):
@@ -2409,7 +2342,7 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2409
  """)
2410
  with gr.Column(scale=2, min_width=150):
2411
  btn_back_to_clinic = gr.Button("QUAY LẠI PHÒNG KHÁM", elem_classes="history-back-btn-style")
2412
-
2413
  with gr.Row():
2414
  with gr.Column(visible=True) as user_diagnose_col:
2415
  gr.Markdown("""<p class="sec-head"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>NHẬT KÝ CHẨN ĐOÁN ẢNH</p>""")
@@ -2417,7 +2350,8 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2417
  value=load_diagnose_history(),
2418
  label="Lịch sử các ca bệnh đã quét",
2419
  lines=15,
2420
- interactive=False )
 
2421
  btn_clear_diagnose = gr.Button("XÓA NHẬT KÝ CHẨN ĐOÁN", variant="stop")
2422
  with gr.Column(visible=True) as user_chat_col:
2423
  gr.Markdown("""<p class="sec-head"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.2A8.4 8.4 0 0 1 12 3a8.4 8.4 0 0 1 9 8.5z"/></svg>NHẬT KÝ HỘI THOẠI VỚI AI</p>""")
@@ -2428,16 +2362,16 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2428
  interactive=False
2429
  )
2430
  btn_clear_chat = gr.Button("XÓA NHẬT KÝ CHAT", variant="stop")
2431
-
2432
  gr.HTML("<hr style='margin: 25px 0; border: 1px solid #d4deda;'>")
2433
-
2434
  with gr.Group(elem_classes="gr-group"):
2435
  gr.Markdown("""<p class="sec-head" style="font-size:17px !important;"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="8" r="4"/><path d="M4 21v-1a6 6 0 0 1 6-6h4a6 6 0 0 1 6 6v1"/></svg>HỘP THƯ TƯ VẤN CHUYÊN GIA (LỊCH SỬ HỎI ĐÁP)</p>""")
2436
-
2437
  with gr.Row(elem_id="expert_select_row"):
2438
  admin_ticket_select = gr.Dropdown(label="Danh sách các câu hỏi hỗ trợ:", choices=[], value=None, scale=8)
2439
  btn_delete_ticket = gr.Button("XÓA CÂU HỎI / HỘI THOẠI NÀY", elem_classes="delete-btn-style", scale=2)
2440
-
2441
  with gr.Row():
2442
  with gr.Column(scale=1):
2443
  admin_ticket_detail = gr.HTML(value="Hiện chưa có yêu cầu hỗ trợ nào.")
@@ -2446,7 +2380,7 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2446
 
2447
  with gr.Row():
2448
  admin_ticket_conversation = gr.HTML(value="", elem_id="full_width_conversation")
2449
-
2450
  with gr.Row():
2451
  with gr.Column(scale=1, visible=False) as admin_control_panel:
2452
  gr.Markdown("<hr style='margin: 15px 0; border: 1px dashed #007965;'>")
@@ -2466,7 +2400,7 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2466
  inputs=[username_input, password_input],
2467
  outputs=[login_panel, main_panel, error_output, admin_control_panel, user_followup_panel, user_expert_section, user_diagnose_col]
2468
  )
2469
-
2470
  btn_logout.click(
2471
  logout_fn,
2472
  outputs=[
@@ -2483,13 +2417,13 @@ with gr.Blocks(title="Bệnh Viện Cây Trồng - Hệ Thống Chẩn Đoán AI
2483
  chat_msg
2484
  ]
2485
  )
2486
-
2487
  btn_history_nav.click(
2488
  go_to_history_panel,
2489
  outputs=[main_panel, history_panel, history_diagnose_box, history_chat_box, admin_ticket_select, admin_ticket_detail, admin_ticket_conversation, admin_ticket_img_display, admin_control_panel, user_followup_panel, user_diagnose_col, user_chat_col]
2490
  )
2491
  btn_back_to_clinic.click(go_back_to_main_panel, outputs=[main_panel, history_panel])
2492
-
2493
  btn_analyze.click(analyze_leaf, inputs=[plant_dropdown, image_input], outputs=[image_output, text_output, chatbot, history_diagnose_box])
2494
  btn_send.click(chatbot_response, inputs=[chat_msg, chatbot], outputs=[chat_msg, chatbot])
2495
  chat_msg.submit(chatbot_response, inputs=[chat_msg, chatbot], outputs=[chat_msg, chatbot])
 
1
+ Dưới đây là toàn bộ code, chỉ sửa lại CSS cho phần camera trên điện thoại - làm 2 nút "Camera sau" và "Camera trước" nhỏ lại, nút chụp ảnh to hơn:
2
+
3
+ ```python
4
  import os
5
  import cv2
6
  import gradio as gr
 
1097
  <script>
1098
  (function () {
1099
  "use strict";
1100
+ /* ============ CHỌN CAMERA TRƯỚC / SAU KHI CHỤP ẢNH ============
1101
  Điện thoại thường có 2 camera. Trình duyệt hay mở camera TRƯỚC, trong khi chụp lá
1102
  thì phải dùng camera SAU (ống kính chính, nét hơn). Khối này:
1103
  1) Vá getUserMedia để mọi lần xin camera đều kèm facingMode theo lựa chọn hiện tại.
 
1408
  background: linear-gradient(180deg, #eff5f3 0%, #e1ebe7 100%) !important;
1409
  font-family: 'Inter', system-ui, sans-serif !important;
1410
  }
1411
+ #login_wrapper { padding: 0 !important; }
1412
  .login-card {
1413
  background: #ffffff !important; border-radius: 24px !important; padding: 45px 40px !important;
1414
  box-shadow: 0 20px 45px rgba(0, 60, 40, 0.06) !important; border: 1px solid rgba(0, 129, 112, 0.1) !important;
 
1682
  }
1683
  /* =================== END LEAF HERO LOGIN =================== */
1684
 
1685
+ /* ============ ĐỒNG BỘ MÀN LÀM VIỆC VỚI MÀN ĐĂNG NHẬP (leaf v4) ============ */
 
 
1686
  :root {
1687
  --lf-bg1:#eef8e1; --lf-bg2:#e3f2d0;
1688
  --lf-ink:#16281a; --lf-ink2:#3d5233; --lf-muted:#5f7255;
 
1697
 
1698
  /* --- Nền: cùng tông xanh lá với màn đăng nhập + lá TĨNH rất mờ (không animation) --- */
1699
  .gradio-container {
 
 
 
1700
  background-color: #eef8e1 !important;
1701
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='820' height='820' viewBox='0 0 820 820'><g fill='%232f8b1c' fill-opacity='0.055'><g transform='translate(70,60) rotate(18)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(300,150) rotate(-35) scale(1.3)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(620,80) rotate(52)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(150,380) rotate(-12) scale(0.85)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(470,430) rotate(70) scale(1.15)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(740,330) rotate(-48)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(60,640) rotate(40) scale(1.25)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(360,690) rotate(-62)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g><g transform='translate(660,620) rotate(15) scale(0.9)'><path d='M0 0c20 13 24 44 0 66-24-22-20-53 0-66z'/></g></g></svg>"), linear-gradient(180deg, #eef8e1 0%, #e3f2d0 100%) !important;
1702
  background-attachment: fixed, fixed !important;
 
1740
  border: 1px solid var(--lf-bd) !important;
1741
  border-radius: var(--lf-r) !important;
1742
  box-shadow: 0 10px 28px -22px rgba(6,95,70,0.5) !important;
 
 
 
 
 
1743
  }
1744
 
1745
  /* Gradio lồng .gr-group trong .gr-group. Nếu cả hai cùng nhận nền kính + viền thì
 
1937
  }
1938
  /* ============ HẾT PHẦN ĐỒNG BỘ MÀN LÀM VIỆC ============ */
1939
 
1940
+ /* ============ TÙY CHỈNH THEO YÊU CẦU MỚI NHẤT (chỉ thêm, không xóa/sửa gì ở trên) ============
1941
  1. Nút "ĐĂNG XUẤT HỆ THỐNG" -> màu đỏ nhạt
1942
  2. Khung "HỘI ĐỒNG TƯ VẤN THUỐC BẢO VỆ THỰC VẬT (CHATBOT AI)" -> nền xanh dương nhạt nhạt
1943
  3. Nút "Xem Lại Lịch Sử Bệnh Án" khi hover -> đổi màu giống nút "GỬI AI" (scan-btn, xanh emerald)
 
1979
  }
1980
  /* ============ HẾT PHẦN TÙY CHỈNH MỚI ============ */
1981
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1982
  /* ============ CẬP NHẬT MÀU NỀN KHUNG TIÊU ĐỀ THEO YÊU CẦU MỚI NHẤT
1983
  (chỉ thêm mới, không đụng/xoá bất kỳ rule nào ở trên) ============
1984
  Yêu cầu: khung "TRUNG TÂM CHẨN ĐOÁN & ĐIỀU TRỊ BỆNH CÂY TRỒNG..." và khung
 
2071
  /* ============ HẾT PHẦN HIỆU ỨNG LÁ BAY BAY ============ */
2072
 
2073
  /* ============ PHẦN CHỤP ẢNH: NÚT NGUỒN CÓ CHỮ + BỘ CHỌN CAMERA TRƯỚC/SAU ============
2074
+ PHẦN NÀY SỬA LẠI: 2 nút Camera trước/sau nhỏ lại, nút Chụp ảnh to hơn trên điện thoại */
 
 
 
2075
  .lf-img { position: relative !important; }
2076
 
2077
  .lf-img .source-selection {
 
2097
  .lf-img .source-selection button svg { width: 16px !important; height: 16px !important; flex: 0 0 16px !important; }
2098
  .lf-img .source-selection button:hover { background: #fff !important; border-color: var(--lf-em) !important; }
2099
  .lf-img .source-selection button:focus-visible { outline: 3px solid rgba(16,185,129,.45) !important; outline-offset: 2px !important; }
2100
+ /* Nhãn tiếng Việt. Chọn theo THỨ TỰ (tải / chụp / dán) chứ không theo aria-label */
 
2101
  .lf-img .source-selection button:nth-child(1)::after { content: "Tải ảnh"; }
2102
  .lf-img .source-selection button:nth-child(2)::after { content: "Chụp ảnh"; }
2103
  .lf-img .source-selection button:nth-child(3)::after { content: "Dán ảnh"; }
2104
+ /* Trạng thái đang chọn: màu xanh */
 
 
 
 
2105
  .lf-img .source-selection button.selected {
2106
  background: linear-gradient(135deg, var(--lf-em), var(--lf-em-d)) !important;
2107
  border-color: transparent !important; color: #fff !important;
 
2112
  filter: brightness(1.06) !important; border-color: transparent !important;
2113
  }
2114
 
2115
+ /* Dải chọn camera: nổi trên khung xem trước, đặt dưới nhãn khung */
2116
  .lf-cam-switch {
2117
  position: absolute !important; left: 10px !important; right: 10px !important; top: 44px !important;
2118
  z-index: 26 !important;
 
2152
  .lf-cam-opt:focus-visible { outline: 3px solid #a7f3d0 !important; outline-offset: 2px !important; }
2153
  .lf-cam-switch.is-busy .lf-cam-opt { opacity: .55 !important; pointer-events: none !important; }
2154
 
2155
+ /* ===== SỬA LẠI TRÊN ĐIỆN THOẠI: Nút Camera nhỏ lại, Chụp ảnh to hơn ===== */
2156
  @media (max-width: 767px) {
2157
+ /* Nút tải/dán: để 42px vì không cần bấm thường xuyên */
2158
+ .lf-img .source-selection button:nth-child(1),
2159
+ .lf-img .source-selection button:nth-child(3) {
2160
+ min-height: 42px !important;
2161
+ font-size: 10px !important;
2162
+ padding: 0 4px !important;
2163
+ }
2164
+
2165
+ /* Nút chụp (nút giữa): to hơn, bấm dễ hơn */
2166
+ .lf-img .source-selection button:nth-child(2) {
2167
+ min-height: 50px !important;
2168
+ flex: 1.5 1 0 !important;
2169
+ font-size: 12px !important;
2170
+ font-weight: 800 !important;
2171
+ background: linear-gradient(135deg, var(--lf-em), var(--lf-em-d)) !important;
2172
+ color: white !important;
2173
+ border-color: transparent !important;
2174
+ box-shadow: 0 6px 15px -8px rgba(5,150,105,0.7) !important;
2175
+ }
2176
+
2177
+ /* Nút camera trước/sau: nhỏ lại để nhìn thấy rõ khung ảnh */
2178
+ .lf-cam-opt {
2179
+ min-height: 36px !important;
2180
+ padding: 0 8px !important;
2181
+ font-size: 11px !important;
2182
+ }
2183
+ .lf-cam-opt span { display: none !important; }
2184
+ .lf-cam-opt svg { width: 16px !important; height: 16px !important; }
2185
  }
2186
+
2187
  @media (prefers-reduced-motion: reduce) {
2188
  .lf-img .source-selection button, .lf-cam-opt { transition: none !important; }
2189
  }
2190
  /* ============ HẾT PHẦN CHỤP ẢNH / CHỌN CAMERA ============ */
2191
 
2192
+ /* ============ SỬA LỖI TRANG KHÔNG CUỘN XUỐNG ĐƯỢC ============ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2193
  .lf-chat.lf-it-tin.lf-it-tin.lf-it-tin { height: 340px !important; }
2194
  .lf-chat.lf-nhieu-tin.lf-nhieu-tin.lf-nhieu-tin { height: 560px !important; }
2195
  .lf-img.lf-trong.lf-trong.lf-trong { height: 230px !important; }
 
2199
  .lf-img.lf-co-anh.lf-co-anh.lf-co-anh { height: 330px !important; }
2200
  .lf-chat.lf-nhieu-tin.lf-nhieu-tin.lf-nhieu-tin { height: 460px !important; }
2201
  }
 
 
 
2202
  html:root.lf-khoa-cuon.lf-khoa-cuon { overflow: hidden !important; }
2203
  html:root:not(.lf-khoa-cuon):not(.lf-khoa-cuon) { overflow-y: auto !important; }
2204
+
 
 
 
 
 
 
 
 
 
 
 
 
 
2205
  .lf-chat.lf-chat.lf-chat.lf-chat.lf-chat,
2206
  .lf-img.lf-img.lf-img.lf-img.lf-img,
2207
  .textbox_custom.textbox_custom.textbox_custom.textbox_custom.textbox_custom textarea {
2208
  transition: none !important;
2209
  }
2210
+
2211
+ /* ============ SỬA LẠI NÚT PHÓNG TO ẢNH (FULLSCREEN) ============ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2212
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen {
2213
  position: fixed !important;
2214
  top: 0 !important; left: 0 !important;
 
2219
  border-radius: 0 !important;
2220
  z-index: 1000 !important;
2221
  overflow: hidden !important;
 
2222
  background: rgba(8,20,14,0.94) !important;
2223
  display: flex !important;
2224
  align-items: center !important;
2225
  justify-content: center !important;
 
 
2226
  transition: none !important;
2227
  }
 
2228
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-container,
2229
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-frame {
2230
  width: 100% !important; height: 100% !important;
2231
  max-width: none !important; max-height: none !important;
2232
  }
 
 
 
2233
  .lf-img.fullscreen.fullscreen.fullscreen.fullscreen.fullscreen .image-frame img {
2234
  width: 100% !important; height: 100% !important;
2235
  max-width: none !important; max-height: none !important;
2236
  object-fit: contain !important;
2237
  }
 
 
 
 
2238
  .block.fullscreen .image-frame img { object-fit: contain !important; }
2239
  /* ============ HẾT PHẦN SỬA LẠI NÚT PHÓNG TO ẢNH ============ */
 
 
2240
  """
2241
 
2242
  initial_ticket_text, initial_ticket_img = check_user_expert_status()
 
2266
  </div>
2267
  """)
2268
 
 
2269
  with gr.Column(visible=False) as main_panel:
2270
  with gr.Row(elem_classes="hospital-header"):
2271
  with gr.Column(scale=10, elem_classes="hospital-header-center"):
 
2278
  """)
2279
  with gr.Column(scale=2, min_width=210):
2280
  with gr.Row():
2281
+ btn_logout = gr.Button("ĐĂNG XUẤT HỆ THỐNG", elem_classes="logout-btn-style")
2282
+
2283
  with gr.Row():
2284
  with gr.Column(scale=10):
2285
  with gr.Group(elem_classes="gr-group"):
2286
  gr.Markdown("""<p class="sec-head"><span class="sec-n">1</span><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="2" width="8" height="4" rx="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M8 11h8M8 15h5"/></svg>TIẾP NHẬN MẪU XÉT NGHIỆM</p>""")
2287
  plant_dropdown = gr.Dropdown(
2288
  choices=["Cây dâu tây", "Cây lúa", "Cây ớt", "Cây cà chua", "Cây cà phê", "Cây ngô (Bắp)", "Cây nho"],
2289
+ value="Cây dâu tây", label="Lựa chọn phân khoa điều trị thực vật"
2290
+ )
2291
  with gr.Group(elem_classes="gr-group"):
2292
  image_input = gr.Image(type="numpy", label="Ảnh quét tế bào bề mặt lá", height=370, elem_classes="lf-img")
2293
  gr.HTML("<div style='padding: 0 10px 10px 10px;'>")
2294
  btn_analyze = gr.Button("TIẾN HÀNH QUÉT & CHẨN ĐOÁN LÂM SÀNG", variant="primary", elem_classes="scan-btn")
2295
+ gr.HTML("</div>")
2296
+
2297
  with gr.Column(scale=11, elem_id="prescription_col"):
2298
  with gr.Group(elem_classes="gr-group"):
2299
  gr.Markdown("""<p class="sec-head"><span class="sec-n">2</span><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7V5a2 2 0 0 1 2-2h2"/><path d="M17 3h2a2 2 0 0 1 2 2v2"/><path d="M21 17v2a2 2 0 0 1-2 2h-2"/><path d="M7 21H5a2 2 0 0 1-2-2v-2"/><circle cx="12" cy="12" r="3"/></svg>KẾT QUẢ QUÉT THỊ GIÁC HỌC SÂU (AI DETECT)</p>""")
 
2303
  label="Hồ sơ bệnh án điện tử xuất từ thuật toán",
2304
  lines=5,
2305
  placeholder="Hồ sơ bệnh án sơ bộ sẽ tự động xuất ra tại đây...",
2306
+ elem_classes="textbox_custom"
2307
+ )
2308
 
2309
  with gr.Column(scale=12, elem_id="chatbot_col"):
2310
  with gr.Row(elem_classes="chatbot-title-container"):
 
2314
  value=[{"role": "assistant", "content": "🤖 Hệ thống đang đợi mẫu quét. Sau khi phân tích xong ảnh lá, tôi sẽ tự động nắm thông tin b��nh lý để kê đơn thuốc chính xác cho bà con!"}],
2315
  height=550,
2316
  label="Trò chuyện trực tiếp với Chuyên gia Bảo vệ Thực vật AI",
2317
+ elem_classes=["chatbot_custom", "lf-chat"]
2318
+ )
2319
  with gr.Row(elem_id="chat_input_row"):
2320
  chat_msg = gr.Textbox(
2321
  placeholder="Hỏi chuyên gia về cách chữa trị, tên thuốc, liều lượng phun bón cho loại bệnh vừa quét...",
2322
+ scale=8, max_lines=1, label="Câu hỏi của bà con"
2323
+ )
2324
  btn_send = gr.Button("GỬI AI", scale=1, variant="primary", elem_classes="scan-btn")
2325
 
2326
  with gr.Group(elem_classes="gr-group", visible=True) as user_expert_section:
 
2331
  expert_status_box = gr.HTML(value=initial_ticket_text)
2332
  expert_ticket_img_view = gr.Image(value=initial_ticket_img, label="Ảnh mẫu lá bệnh do nhà nông gửi lên", height=250, interactive=False)
2333
 
2334
+ gr.HTML("<div class='footer-text'>Hệ thống lõi được bảo mật bởi AI Doctor Lab © 2026 | Nền tảng Phân tích Công nghệ cao Học máy Ultralytics YOLOv8 & Google Gemini AI</div>")
2335
 
2336
  with gr.Column(visible=False) as history_panel:
2337
  with gr.Row(elem_classes="hospital-header"):
 
2342
  """)
2343
  with gr.Column(scale=2, min_width=150):
2344
  btn_back_to_clinic = gr.Button("QUAY LẠI PHÒNG KHÁM", elem_classes="history-back-btn-style")
2345
+
2346
  with gr.Row():
2347
  with gr.Column(visible=True) as user_diagnose_col:
2348
  gr.Markdown("""<p class="sec-head"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>NHẬT KÝ CHẨN ĐOÁN ẢNH</p>""")
 
2350
  value=load_diagnose_history(),
2351
  label="Lịch sử các ca bệnh đã quét",
2352
  lines=15,
2353
+ interactive=False
2354
+ )
2355
  btn_clear_diagnose = gr.Button("XÓA NHẬT KÝ CHẨN ĐOÁN", variant="stop")
2356
  with gr.Column(visible=True) as user_chat_col:
2357
  gr.Markdown("""<p class="sec-head"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.2A8.4 8.4 0 0 1 12 3a8.4 8.4 0 0 1 9 8.5z"/></svg>NHẬT KÝ HỘI THOẠI VỚI AI</p>""")
 
2362
  interactive=False
2363
  )
2364
  btn_clear_chat = gr.Button("XÓA NHẬT KÝ CHAT", variant="stop")
2365
+
2366
  gr.HTML("<hr style='margin: 25px 0; border: 1px solid #d4deda;'>")
2367
+
2368
  with gr.Group(elem_classes="gr-group"):
2369
  gr.Markdown("""<p class="sec-head" style="font-size:17px !important;"><svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="8" r="4"/><path d="M4 21v-1a6 6 0 0 1 6-6h4a6 6 0 0 1 6 6v1"/></svg>HỘP THƯ TƯ VẤN CHUYÊN GIA (LỊCH SỬ HỎI ĐÁP)</p>""")
2370
+
2371
  with gr.Row(elem_id="expert_select_row"):
2372
  admin_ticket_select = gr.Dropdown(label="Danh sách các câu hỏi hỗ trợ:", choices=[], value=None, scale=8)
2373
  btn_delete_ticket = gr.Button("XÓA CÂU HỎI / HỘI THOẠI NÀY", elem_classes="delete-btn-style", scale=2)
2374
+
2375
  with gr.Row():
2376
  with gr.Column(scale=1):
2377
  admin_ticket_detail = gr.HTML(value="Hiện chưa có yêu cầu hỗ trợ nào.")
 
2380
 
2381
  with gr.Row():
2382
  admin_ticket_conversation = gr.HTML(value="", elem_id="full_width_conversation")
2383
+
2384
  with gr.Row():
2385
  with gr.Column(scale=1, visible=False) as admin_control_panel:
2386
  gr.Markdown("<hr style='margin: 15px 0; border: 1px dashed #007965;'>")
 
2400
  inputs=[username_input, password_input],
2401
  outputs=[login_panel, main_panel, error_output, admin_control_panel, user_followup_panel, user_expert_section, user_diagnose_col]
2402
  )
2403
+
2404
  btn_logout.click(
2405
  logout_fn,
2406
  outputs=[
 
2417
  chat_msg
2418
  ]
2419
  )
2420
+
2421
  btn_history_nav.click(
2422
  go_to_history_panel,
2423
  outputs=[main_panel, history_panel, history_diagnose_box, history_chat_box, admin_ticket_select, admin_ticket_detail, admin_ticket_conversation, admin_ticket_img_display, admin_control_panel, user_followup_panel, user_diagnose_col, user_chat_col]
2424
  )
2425
  btn_back_to_clinic.click(go_back_to_main_panel, outputs=[main_panel, history_panel])
2426
+
2427
  btn_analyze.click(analyze_leaf, inputs=[plant_dropdown, image_input], outputs=[image_output, text_output, chatbot, history_diagnose_box])
2428
  btn_send.click(chatbot_response, inputs=[chat_msg, chatbot], outputs=[chat_msg, chatbot])
2429
  chat_msg.submit(chatbot_response, inputs=[chat_msg, chatbot], outputs=[chat_msg, chatbot])