Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,11 @@ import datetime
|
|
| 8 |
import json
|
| 9 |
import numpy as np
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
VN_TIMEZONE = datetime.timezone(datetime.timedelta(hours=7))
|
| 12 |
|
| 13 |
def get_vn_time():
|
|
@@ -258,20 +263,20 @@ def logout_fn():
|
|
| 258 |
|
| 259 |
def get_ticket_status_display(ticket):
|
| 260 |
"""Xác định nhãn trạng thái hiển thị rõ ràng:
|
| 261 |
-
1. 🔵
|
| 262 |
-
2. 🟡
|
| 263 |
-
3. 🔴
|
| 264 |
"""
|
| 265 |
messages = ticket.get("messages", [])
|
| 266 |
has_admin_replied_before = any(m.get("sender") == "ADMIN" for m in messages) or bool(ticket.get("admin_reply"))
|
| 267 |
|
| 268 |
if ticket.get("status") == "PENDING":
|
| 269 |
if has_admin_replied_before:
|
| 270 |
-
return "🟡
|
| 271 |
else:
|
| 272 |
-
return "🔵
|
| 273 |
else:
|
| 274 |
-
return "🔴
|
| 275 |
|
| 276 |
def get_admin_tickets_list(selected_value=None):
|
| 277 |
tickets = load_expert_tickets()
|
|
@@ -1061,7 +1066,18 @@ LEAF_HERO_HEAD = r"""
|
|
| 1061 |
let prevOnLogin = null;
|
| 1062 |
setInterval(function () {
|
| 1063 |
const el = document.getElementById("login_wrapper");
|
| 1064 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1065 |
document.body.classList.toggle("leaf-on", onLogin);
|
| 1066 |
active = onLogin;
|
| 1067 |
if (!onLogin) lastFrame = 0;
|
|
@@ -1471,6 +1487,12 @@ body.leaf-on #leaf-bg { opacity: 1; }
|
|
| 1471 |
body.leaf-on { background: #e8f5d6 !important; margin: 0; padding: 0; height: 100vh; overflow: hidden !important;
|
| 1472 |
font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
|
| 1473 |
html:has(body.leaf-on) { overflow: hidden !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1474 |
body.leaf-on .gradio-container { background: transparent !important; padding: 0 !important; min-height: 0 !important; max-width: none !important; font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important; }
|
| 1475 |
body.leaf-on footer { display: none !important; }
|
| 1476 |
#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; }
|
|
|
|
| 8 |
import json
|
| 9 |
import numpy as np
|
| 10 |
|
| 11 |
+
# --- CẤU HÌNH MÚI GIỜ VIỆT NAM (UTC+7) CHO TOÀN BỘ THỜI GIAN LƯU LỊCH SỬ ---
|
| 12 |
+
# Nguyên nhân giờ bị lệch trước đây: máy chủ (server) chạy theo múi giờ khác Việt Nam
|
| 13 |
+
# (thường là UTC 0), nên datetime.datetime.now() lấy giờ hệ thống của server chứ không
|
| 14 |
+
# phải giờ Việt Nam -> ngày tháng năm đúng nhưng GIỜ bị lệch. Hàm dưới đây luôn quy đổi
|
| 15 |
+
# về đúng giờ Việt Nam (UTC+7) bất kể server đặt múi giờ nào.
|
| 16 |
VN_TIMEZONE = datetime.timezone(datetime.timedelta(hours=7))
|
| 17 |
|
| 18 |
def get_vn_time():
|
|
|
|
| 263 |
|
| 264 |
def get_ticket_status_display(ticket):
|
| 265 |
"""Xác định nhãn trạng thái hiển thị rõ ràng:
|
| 266 |
+
1. 🔵 CHƯA TRẢ LỜI
|
| 267 |
+
2. 🟡 ĐÃ TRẢ LỜI & CÓ HỎI THÊM
|
| 268 |
+
3. 🔴 ĐÃ TRẢ LỜI
|
| 269 |
"""
|
| 270 |
messages = ticket.get("messages", [])
|
| 271 |
has_admin_replied_before = any(m.get("sender") == "ADMIN" for m in messages) or bool(ticket.get("admin_reply"))
|
| 272 |
|
| 273 |
if ticket.get("status") == "PENDING":
|
| 274 |
if has_admin_replied_before:
|
| 275 |
+
return "🟡 ĐÃ TRẢ LỜI & CÓ HỎI THÊM", 1
|
| 276 |
else:
|
| 277 |
+
return "🔵 CHƯA TRẢ LỜI", 0
|
| 278 |
else:
|
| 279 |
+
return "🔴 ĐÃ TRẢ LỜI", 2
|
| 280 |
|
| 281 |
def get_admin_tickets_list(selected_value=None):
|
| 282 |
tickets = load_expert_tickets()
|
|
|
|
| 1066 |
let prevOnLogin = null;
|
| 1067 |
setInterval(function () {
|
| 1068 |
const el = document.getElementById("login_wrapper");
|
| 1069 |
+
let onLogin = !!el && el.offsetParent !== null;
|
| 1070 |
+
/* CHỐT AN TOÀN CHO VIỆC CUỘN TRANG.
|
| 1071 |
+
body.leaf-on khoá cứng trang (height:100vh + overflow:hidden) — đúng cho màn
|
| 1072 |
+
đăng nhập, nhưng THẢM HOẠ nếu lỡ bật nhầm ở màn làm việc: kéo thanh cuộn cũng
|
| 1073 |
+
không xuống được và phần dưới (khung ảnh đã gửi chuyên gia) bị cắt mất.
|
| 1074 |
+
Việc bật/tắt ở trên chỉ dựa vào một phép dò duy nhất là #login_wrapper còn hiện
|
| 1075 |
+
hay không; mỗi lần Gradio dựng lại DOM (rõ nhất là sau khi AI trả lời xong) phép
|
| 1076 |
+
dò đó có thể đọc nhầm trong khoảnh khắc chuyển tiếp, và trang kẹt luôn.
|
| 1077 |
+
Khung chat chỉ tồn tại ở màn làm việc, nên nó đang hiện thì chắc chắn KHÔNG phải
|
| 1078 |
+
màn đăng nhập — dù phép dò kia nói gì. Lấy đó làm chốt chặn cuối. */
|
| 1079 |
+
const chat = document.querySelector(".lf-chat");
|
| 1080 |
+
if (chat && chat.offsetParent !== null) onLogin = false;
|
| 1081 |
document.body.classList.toggle("leaf-on", onLogin);
|
| 1082 |
active = onLogin;
|
| 1083 |
if (!onLogin) lastFrame = 0;
|
|
|
|
| 1487 |
body.leaf-on { background: #e8f5d6 !important; margin: 0; padding: 0; height: 100vh; overflow: hidden !important;
|
| 1488 |
font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
|
| 1489 |
html:has(body.leaf-on) { overflow: hidden !important; }
|
| 1490 |
+
/* LỚP BẢO HIỂM CUỘN TRANG: hai rule ngay trên khoá cứng trang cho màn đăng nhập.
|
| 1491 |
+
Rời khỏi màn đăng nhập (không còn class leaf-on) thì trang PHẢI cuộn lại được ngay,
|
| 1492 |
+
nói rõ ra bằng !important thay vì trông chờ giá trị mặc định — vì chỉ cần khoá còn
|
| 1493 |
+
sót lại là bà con không kéo nổi thanh cuộn xuống xem khung ảnh dưới cùng. */
|
| 1494 |
+
body:not(.leaf-on) { overflow-y: auto !important; height: auto !important; }
|
| 1495 |
+
html:not(:has(body.leaf-on)) { overflow-y: auto !important; }
|
| 1496 |
body.leaf-on .gradio-container { background: transparent !important; padding: 0 !important; min-height: 0 !important; max-width: none !important; font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important; }
|
| 1497 |
body.leaf-on footer { display: none !important; }
|
| 1498 |
#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; }
|