Spaces:
Runtime error
Runtime error
J.B-Lin commited on
Commit ·
765f642
1
Parent(s): fb89443
fix: 三天总结营养素名中英文双语显示 + CSS消除灰色填充和双重方框
Browse files
utils.py
CHANGED
|
@@ -457,6 +457,41 @@ def render_nutrition_report_html(analysis: dict, days: int, lang="zh") -> str:
|
|
| 457 |
</div>"""
|
| 458 |
|
| 459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
# ============================================================
|
| 461 |
# 三天缺失深度分析 HTML(与营养报告统一视觉风格)
|
| 462 |
# ============================================================
|
|
@@ -492,16 +527,17 @@ def render_three_day_deficit_section(deficit_data: dict, lang="zh") -> str:
|
|
| 492 |
{no_data_msg}
|
| 493 |
</div>"""
|
| 494 |
|
| 495 |
-
# ——— 构建缺失营养素的卡片 ———
|
| 496 |
deficit_cards = ""
|
| 497 |
for nutrient in persistent_deficits:
|
|
|
|
| 498 |
deficit_cards += f"""
|
| 499 |
<div style="background:#fff;border-radius:14px;padding:14px 16px;
|
| 500 |
box-shadow:0 1px 6px rgba(0,0,0,0.04);border:1px solid #FFCDD2;
|
| 501 |
transition:all 0.2s;display:flex;align-items:center;gap:12px;">
|
| 502 |
<div style="font-size:24px;min-width:36px;text-align:center;">⚠️</div>
|
| 503 |
<div>
|
| 504 |
-
<div style="font-weight:600;font-size:15px;color:#C62828;">{
|
| 505 |
<div style="font-size:12px;color:#888;margin-top:2px;">{t("three_day_deficit", lang)}</div>
|
| 506 |
</div>
|
| 507 |
</div>"""
|
|
@@ -521,6 +557,7 @@ def render_three_day_deficit_section(deficit_data: dict, lang="zh") -> str:
|
|
| 521 |
from modules.nutrition_standards import DRIsParser
|
| 522 |
suggestion_items = ""
|
| 523 |
for nutrient in persistent_deficits[:3]:
|
|
|
|
| 524 |
foods = DRIsParser.RICH_FOODS.get(nutrient, [])
|
| 525 |
if foods:
|
| 526 |
food_tags = "".join(
|
|
@@ -531,7 +568,7 @@ def render_three_day_deficit_section(deficit_data: dict, lang="zh") -> str:
|
|
| 531 |
suggestion_items += f"""
|
| 532 |
<div style="margin-bottom:12px;">
|
| 533 |
<div style="font-weight:600;font-size:14px;color:#E91E63;margin-bottom:6px;">
|
| 534 |
-
💪 {
|
| 535 |
</div>
|
| 536 |
<div style="display:flex;flex-wrap:wrap;gap:6px;">
|
| 537 |
{food_tags}
|
|
@@ -790,6 +827,54 @@ input, textarea, .gr-textbox {
|
|
| 790 |
box-shadow: none !important;
|
| 791 |
}
|
| 792 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 793 |
/* 消除 Trimester 卡�� group 的双层边框 */
|
| 794 |
.card-trimester.gr-group,
|
| 795 |
.card-trimester .gr-box {
|
|
|
|
| 457 |
</div>"""
|
| 458 |
|
| 459 |
|
| 460 |
+
# ============================================================
|
| 461 |
+
# 营养素中英文对照表(用于三天总结双语展示)
|
| 462 |
+
# ============================================================
|
| 463 |
+
|
| 464 |
+
NUTRIENT_EN_NAMES = {
|
| 465 |
+
"能量(MJ)": "Energy",
|
| 466 |
+
"蛋白质(g)": "Protein",
|
| 467 |
+
"钙(mg)": "Calcium",
|
| 468 |
+
"铁(mg)": "Iron",
|
| 469 |
+
"锌(mg)": "Zinc",
|
| 470 |
+
"维生素A(μg RAE)": "Vitamin A",
|
| 471 |
+
"维生素D(μg)": "Vitamin D",
|
| 472 |
+
"维生素E(mg α-TE)": "Vitamin E",
|
| 473 |
+
"维生素B1(mg)": "Vitamin B1",
|
| 474 |
+
"维生素B2(mg)": "Vitamin B2",
|
| 475 |
+
"叶酸(μg DFE)": "Folate",
|
| 476 |
+
"碘(μg)": "Iodine",
|
| 477 |
+
"镁(mg)": "Magnesium",
|
| 478 |
+
"硒(μg)": "Selenium",
|
| 479 |
+
"钾(mg)": "Potassium",
|
| 480 |
+
"钠(mg)": "Sodium",
|
| 481 |
+
"磷(mg)": "Phosphorus",
|
| 482 |
+
"维生素C(mg)": "Vitamin C",
|
| 483 |
+
"膳食纤维(g)": "Dietary Fiber",
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def _nutrient_display(name_cn: str, lang: str) -> str:
|
| 488 |
+
"""返回营养素名的展示文本(中文模式显示中文+英文,英文模式显示英文)"""
|
| 489 |
+
en_name = NUTRIENT_EN_NAMES.get(name_cn, name_cn)
|
| 490 |
+
if lang == "zh":
|
| 491 |
+
return f"{name_cn} / {en_name}"
|
| 492 |
+
return en_name
|
| 493 |
+
|
| 494 |
+
|
| 495 |
# ============================================================
|
| 496 |
# 三天缺失深度分析 HTML(与营养报告统一视觉风格)
|
| 497 |
# ============================================================
|
|
|
|
| 527 |
{no_data_msg}
|
| 528 |
</div>"""
|
| 529 |
|
| 530 |
+
# ——— 构建缺失营养素的卡片(中英文双语) ———
|
| 531 |
deficit_cards = ""
|
| 532 |
for nutrient in persistent_deficits:
|
| 533 |
+
nd = _nutrient_display(nutrient, lang)
|
| 534 |
deficit_cards += f"""
|
| 535 |
<div style="background:#fff;border-radius:14px;padding:14px 16px;
|
| 536 |
box-shadow:0 1px 6px rgba(0,0,0,0.04);border:1px solid #FFCDD2;
|
| 537 |
transition:all 0.2s;display:flex;align-items:center;gap:12px;">
|
| 538 |
<div style="font-size:24px;min-width:36px;text-align:center;">⚠️</div>
|
| 539 |
<div>
|
| 540 |
+
<div style="font-weight:600;font-size:15px;color:#C62828;">{nd}</div>
|
| 541 |
<div style="font-size:12px;color:#888;margin-top:2px;">{t("three_day_deficit", lang)}</div>
|
| 542 |
</div>
|
| 543 |
</div>"""
|
|
|
|
| 557 |
from modules.nutrition_standards import DRIsParser
|
| 558 |
suggestion_items = ""
|
| 559 |
for nutrient in persistent_deficits[:3]:
|
| 560 |
+
nd = _nutrient_display(nutrient, lang)
|
| 561 |
foods = DRIsParser.RICH_FOODS.get(nutrient, [])
|
| 562 |
if foods:
|
| 563 |
food_tags = "".join(
|
|
|
|
| 568 |
suggestion_items += f"""
|
| 569 |
<div style="margin-bottom:12px;">
|
| 570 |
<div style="font-weight:600;font-size:14px;color:#E91E63;margin-bottom:6px;">
|
| 571 |
+
💪 {nd}
|
| 572 |
</div>
|
| 573 |
<div style="display:flex;flex-wrap:wrap;gap:6px;">
|
| 574 |
{food_tags}
|
|
|
|
| 827 |
box-shadow: none !important;
|
| 828 |
}
|
| 829 |
|
| 830 |
+
/* ======== 消除所有Gradio容器的灰色填充和双重边框 ======== */
|
| 831 |
+
|
| 832 |
+
/* 消除所有 Group/Box 的灰色背景 */
|
| 833 |
+
.gr-group, .gr-box, .gr-form, .gr-panel {
|
| 834 |
+
background: transparent !important;
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
/* 消除所有文本输入区域的灰色填充 */
|
| 838 |
+
textarea, input[type="text"], input[type="number"], input[type="search"],
|
| 839 |
+
input[type="email"], input[type="password"], input[type="url"],
|
| 840 |
+
.gr-textarea, .gr-textbox, .gr-input {
|
| 841 |
+
background: #fff !important;
|
| 842 |
+
border-color: #e0e0e0 !important;
|
| 843 |
+
box-shadow: none !important;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
/* 消除焦点时的双重外框 */
|
| 847 |
+
textarea:focus, input:focus, .gr-textarea:focus, .gr-textbox:focus {
|
| 848 |
+
outline: none !important;
|
| 849 |
+
border-color: #E91E63 !important;
|
| 850 |
+
box-shadow: 0 0 0 2px rgba(233, 30, 99, 0.15) !important;
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
/* Gradio button/input wrap 容器 — 去除额外边框 */
|
| 854 |
+
.gr-box > .gr-textarea, .gr-box > .gr-textbox,
|
| 855 |
+
.gr-form > .gr-box, .gr-group > .gr-box {
|
| 856 |
+
border: none !important;
|
| 857 |
+
background: transparent !important;
|
| 858 |
+
box-shadow: none !important;
|
| 859 |
+
}
|
| 860 |
+
|
| 861 |
+
/* 所有卡片容器白色背景 + 取消默认边框 */
|
| 862 |
+
.home-card, .home-card.gr-group, .home-card .gr-box {
|
| 863 |
+
background: #fff !important;
|
| 864 |
+
border: 1px solid #f0f0f0 !important;
|
| 865 |
+
border-radius: 16px !important;
|
| 866 |
+
box-shadow: 0 1px 8px rgba(0,0,0,0.04) !important;
|
| 867 |
+
}
|
| 868 |
+
|
| 869 |
+
/* 消除 Gr.Group 默认灰色内边 */
|
| 870 |
+
.gr-group {
|
| 871 |
+
background: transparent !important;
|
| 872 |
+
border: none !important;
|
| 873 |
+
box-shadow: none !important;
|
| 874 |
+
padding: 0 !important;
|
| 875 |
+
gap: 0 !important;
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
/* 消除 Trimester 卡�� group 的双层边框 */
|
| 879 |
.card-trimester.gr-group,
|
| 880 |
.card-trimester .gr-box {
|