Spaces:
Sleeping
Sleeping
Redesign UI: Tech/Sunny/Humanistic/Sci-Fi theme with watermarks
Browse files
app.py
CHANGED
|
@@ -557,13 +557,220 @@ def export_pdf(history, subject):
|
|
| 557 |
# ============================================================
|
| 558 |
# 5. Gradio 介面
|
| 559 |
# ============================================================
|
| 560 |
-
THEME = gr.themes.
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
"""
|
| 566 |
|
|
|
|
| 567 |
LATEX_DELIMS = [
|
| 568 |
{"left": "$$", "right": "$$", "display": True},
|
| 569 |
{"left": "$", "right": "$", "display": False},
|
|
|
|
| 557 |
# ============================================================
|
| 558 |
# 5. Gradio 介面
|
| 559 |
# ============================================================
|
| 560 |
+
THEME = gr.themes.Base(
|
| 561 |
+
primary_hue=gr.themes.Color(
|
| 562 |
+
c50="#E0F7FF", c100="#B8EBFF", c200="#7FDCFF", c300="#3DC8FF",
|
| 563 |
+
c400="#00D4FF", c500="#00B8DB", c600="#0091AD", c700="#006B82",
|
| 564 |
+
c800="#004A5C", c900="#002A36", c950="#0B1426",
|
| 565 |
+
),
|
| 566 |
+
secondary_hue=gr.themes.Color(
|
| 567 |
+
c50="#FFF5DC", c100="#FFE6A8", c200="#FFD370", c300="#FFC347",
|
| 568 |
+
c400="#FFB627", c500="#F59E0B", c600="#D97706", c700="#B45309",
|
| 569 |
+
c800="#92400E", c900="#78350F", c950="#451A03",
|
| 570 |
+
),
|
| 571 |
+
neutral_hue=gr.themes.Color(
|
| 572 |
+
c50="#F1FAEE", c100="#E2EBE0", c200="#C5D6C2", c300="#A8C2A4",
|
| 573 |
+
c400="#7BA075", c500="#4E7E47", c600="#3D6537", c700="#2C4C28",
|
| 574 |
+
c800="#1B331A", c900="#1B2A4E", c950="#0B1426",
|
| 575 |
+
),
|
| 576 |
+
).set(
|
| 577 |
+
body_background_fill="#0B1426",
|
| 578 |
+
body_background_fill_dark="#0B1426",
|
| 579 |
+
body_text_color="#F1FAEE",
|
| 580 |
+
body_text_color_dark="#F1FAEE",
|
| 581 |
+
background_fill_primary="#1B2A4E",
|
| 582 |
+
background_fill_primary_dark="#1B2A4E",
|
| 583 |
+
background_fill_secondary="#0B1426",
|
| 584 |
+
background_fill_secondary_dark="#0B1426",
|
| 585 |
+
block_background_fill="rgba(27, 42, 78, 0.6)",
|
| 586 |
+
block_background_fill_dark="rgba(27, 42, 78, 0.6)",
|
| 587 |
+
block_border_color="rgba(0, 212, 255, 0.25)",
|
| 588 |
+
block_border_color_dark="rgba(0, 212, 255, 0.25)",
|
| 589 |
+
block_label_background_fill="rgba(0, 212, 255, 0.1)",
|
| 590 |
+
block_label_text_color="#00D4FF",
|
| 591 |
+
input_background_fill="rgba(11, 20, 38, 0.6)",
|
| 592 |
+
input_background_fill_dark="rgba(11, 20, 38, 0.6)",
|
| 593 |
+
input_border_color="rgba(0, 212, 255, 0.3)",
|
| 594 |
+
button_primary_background_fill="linear-gradient(135deg, #00D4FF 0%, #A663CC 100%)",
|
| 595 |
+
button_primary_background_fill_dark="linear-gradient(135deg, #00D4FF 0%, #A663CC 100%)",
|
| 596 |
+
button_primary_text_color="#0B1426",
|
| 597 |
+
button_secondary_background_fill="linear-gradient(135deg, #FF6B6B 0%, #FFB627 100%)",
|
| 598 |
+
button_secondary_background_fill_dark="linear-gradient(135deg, #FF6B6B 0%, #FFB627 100%)",
|
| 599 |
+
button_secondary_text_color="#0B1426",
|
| 600 |
+
)
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
# === 浮水印 SVG(四角:AI / 機器人 / 無人機 / IC)===
|
| 604 |
+
_WM_AI = """<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200' fill='none' stroke='%2300D4FF' stroke-width='1.5'><circle cx='40' cy='60' r='5' fill='%2300D4FF'/><circle cx='40' cy='100' r='5' fill='%2300D4FF'/><circle cx='40' cy='140' r='5' fill='%2300D4FF'/><circle cx='100' cy='40' r='5' fill='%2300D4FF'/><circle cx='100' cy='80' r='5' fill='%2300D4FF'/><circle cx='100' cy='120' r='5' fill='%2300D4FF'/><circle cx='100' cy='160' r='5' fill='%2300D4FF'/><circle cx='160' cy='70' r='5' fill='%2300D4FF'/><circle cx='160' cy='130' r='5' fill='%2300D4FF'/><line x1='40' y1='60' x2='100' y2='40'/><line x1='40' y1='60' x2='100' y2='80'/><line x1='40' y1='60' x2='100' y2='120'/><line x1='40' y1='100' x2='100' y2='40'/><line x1='40' y1='100' x2='100' y2='80'/><line x1='40' y1='100' x2='100' y2='120'/><line x1='40' y1='100' x2='100' y2='160'/><line x1='40' y1='140' x2='100' y2='80'/><line x1='40' y1='140' x2='100' y2='120'/><line x1='40' y1='140' x2='100' y2='160'/><line x1='100' y1='40' x2='160' y2='70'/><line x1='100' y1='80' x2='160' y2='70'/><line x1='100' y1='80' x2='160' y2='130'/><line x1='100' y1='120' x2='160' y2='70'/><line x1='100' y1='120' x2='160' y2='130'/><line x1='100' y1='160' x2='160' y2='130'/></svg>"""
|
| 605 |
+
|
| 606 |
+
_WM_ROBOT = """<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200' fill='none' stroke='%23FFB627' stroke-width='2'><rect x='60' y='40' width='80' height='70' rx='8'/><line x1='100' y1='40' x2='100' y2='25'/><circle cx='100' cy='22' r='4' fill='%23FFB627'/><circle cx='80' cy='70' r='6' fill='%23FFB627'/><circle cx='120' cy='70' r='6' fill='%23FFB627'/><rect x='80' y='90' width='40' height='6' rx='3'/><rect x='50' y='115' width='100' height='65' rx='6'/><rect x='75' y='130' width='50' height='35' rx='3'/><line x1='80' y1='140' x2='120' y2='140'/><line x1='80' y1='150' x2='115' y2='150'/><line x1='80' y1='158' x2='105' y2='158'/><line x1='50' y1='125' x2='35' y2='155'/><line x1='150' y1='125' x2='165' y2='155'/><circle cx='35' cy='158' r='5'/><circle cx='165' cy='158' r='5'/></svg>"""
|
| 607 |
+
|
| 608 |
+
_WM_DRONE = """<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 220 220' fill='none' stroke='%23A663CC' stroke-width='2'><circle cx='110' cy='110' r='15'/><rect x='98' y='98' width='24' height='24' rx='4'/><line x1='110' y1='110' x2='50' y2='50'/><line x1='110' y1='110' x2='170' y2='50'/><line x1='110' y1='110' x2='50' y2='170'/><line x1='110' y1='110' x2='170' y2='170'/><circle cx='50' cy='50' r='28' stroke-dasharray='4 4'/><circle cx='50' cy='50' r='20'/><circle cx='170' cy='50' r='28' stroke-dasharray='4 4'/><circle cx='170' cy='50' r='20'/><circle cx='50' cy='170' r='28' stroke-dasharray='4 4'/><circle cx='50' cy='170' r='20'/><circle cx='170' cy='170' r='28' stroke-dasharray='4 4'/><circle cx='170' cy='170' r='20'/><line x1='30' y1='50' x2='70' y2='50'/><line x1='50' y1='30' x2='50' y2='70'/><line x1='150' y1='50' x2='190' y2='50'/><line x1='170' y1='30' x2='170' y2='70'/><line x1='30' y1='170' x2='70' y2='170'/><line x1='50' y1='150' x2='50' y2='190'/><line x1='150' y1='170' x2='190' y2='170'/><line x1='170' y1='150' x2='170' y2='190'/><circle cx='110' cy='110' r='4' fill='%23A663CC'/></svg>"""
|
| 609 |
+
|
| 610 |
+
_WM_IC = """<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 200' fill='none' stroke='%23A8DADC' stroke-width='1.5'><rect x='80' y='65' width='80' height='70' rx='2'/><line x1='95' y1='55' x2='95' y2='65'/><line x1='110' y1='55' x2='110' y2='65'/><line x1='125' y1='55' x2='125' y2='65'/><line x1='140' y1='55' x2='140' y2='65'/><line x1='95' y1='135' x2='95' y2='145'/><line x1='110' y1='135' x2='110' y2='145'/><line x1='125' y1='135' x2='125' y2='145'/><line x1='140' y1='135' x2='140' y2='145'/><line x1='70' y1='80' x2='80' y2='80'/><line x1='70' y1='95' x2='80' y2='95'/><line x1='70' y1='110' x2='80' y2='110'/><line x1='70' y1='125' x2='80' y2='125'/><line x1='160' y1='80' x2='170' y2='80'/><line x1='160' y1='95' x2='170' y2='95'/><line x1='160' y1='110' x2='170' y2='110'/><line x1='160' y1='125' x2='170' y2='125'/><path d='M 30 80 L 70 80 M 30 80 L 30 30 L 90 30 L 90 55'/><path d='M 30 110 L 70 110'/><path d='M 30 125 L 70 125 L 30 160 L 110 160 L 110 145'/><path d='M 170 80 L 210 80 L 210 30 L 140 30 L 140 55'/><path d='M 170 95 L 200 95'/><path d='M 170 110 L 210 110 L 210 160 L 125 160 L 125 145'/><rect x='22' y='45' width='14' height='6' rx='1'/><rect x='22' y='125' width='14' height='6' rx='1'/><rect x='200' y='45' width='14' height='6' rx='1'/><circle cx='29' cy='160' r='3'/><circle cx='207' cy='125' r='3'/></svg>"""
|
| 611 |
+
|
| 612 |
+
import urllib.parse as _urlparse
|
| 613 |
+
def _svg_data_url(svg_str):
|
| 614 |
+
return "data:image/svg+xml;utf8," + _urlparse.quote(svg_str, safe="")
|
| 615 |
+
|
| 616 |
+
_WM_AI_URL = _svg_data_url(_WM_AI)
|
| 617 |
+
_WM_ROBOT_URL = _svg_data_url(_WM_ROBOT)
|
| 618 |
+
_WM_DRONE_URL = _svg_data_url(_WM_DRONE)
|
| 619 |
+
_WM_IC_URL = _svg_data_url(_WM_IC)
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
CUSTOM_CSS = f"""
|
| 623 |
+
/* ===== 工程解題助手 · 科技/陽光/人文/科幻 主題 ===== */
|
| 624 |
+
|
| 625 |
+
.gradio-container {{
|
| 626 |
+
max-width: 1180px !important;
|
| 627 |
+
background:
|
| 628 |
+
radial-gradient(circle at 15% 20%, rgba(0, 212, 255, 0.10) 0%, transparent 40%),
|
| 629 |
+
radial-gradient(circle at 85% 80%, rgba(255, 182, 39, 0.08) 0%, transparent 40%),
|
| 630 |
+
radial-gradient(circle at 50% 50%, rgba(166, 99, 204, 0.05) 0%, transparent 55%),
|
| 631 |
+
linear-gradient(180deg, #0B1426 0%, #1B2A4E 100%) !important;
|
| 632 |
+
color: #F1FAEE !important;
|
| 633 |
+
position: relative;
|
| 634 |
+
min-height: 100vh;
|
| 635 |
+
}}
|
| 636 |
+
|
| 637 |
+
/* === 浮水印(固定在 viewport 四角,z-index 為 0)=== */
|
| 638 |
+
.gradio-container::before, .gradio-container::after {{
|
| 639 |
+
content: "";
|
| 640 |
+
position: fixed;
|
| 641 |
+
width: 240px;
|
| 642 |
+
height: 240px;
|
| 643 |
+
pointer-events: none;
|
| 644 |
+
opacity: 0.10;
|
| 645 |
+
z-index: 0;
|
| 646 |
+
background-repeat: no-repeat;
|
| 647 |
+
background-size: contain;
|
| 648 |
+
}}
|
| 649 |
+
.gradio-container::before {{
|
| 650 |
+
top: 60px; left: 20px;
|
| 651 |
+
background-image: url("{_WM_AI_URL}");
|
| 652 |
+
}}
|
| 653 |
+
.gradio-container::after {{
|
| 654 |
+
bottom: 30px; right: 20px;
|
| 655 |
+
background-image: url("{_WM_IC_URL}");
|
| 656 |
+
}}
|
| 657 |
+
body::before, body::after {{
|
| 658 |
+
content: "";
|
| 659 |
+
position: fixed;
|
| 660 |
+
width: 220px;
|
| 661 |
+
height: 220px;
|
| 662 |
+
pointer-events: none;
|
| 663 |
+
opacity: 0.10;
|
| 664 |
+
z-index: 0;
|
| 665 |
+
background-repeat: no-repeat;
|
| 666 |
+
background-size: contain;
|
| 667 |
+
}}
|
| 668 |
+
body::before {{
|
| 669 |
+
top: 80px; right: 30px;
|
| 670 |
+
background-image: url("{_WM_ROBOT_URL}");
|
| 671 |
+
}}
|
| 672 |
+
body::after {{
|
| 673 |
+
bottom: 80px; left: 30px;
|
| 674 |
+
background-image: url("{_WM_DRONE_URL}");
|
| 675 |
+
}}
|
| 676 |
+
|
| 677 |
+
/* 內容層放在浮水印之上 */
|
| 678 |
+
.gradio-container > * {{ position: relative; z-index: 1; }}
|
| 679 |
+
|
| 680 |
+
/* === 文字配色 === */
|
| 681 |
+
.gradio-container, .gradio-container * {{ color: #F1FAEE; }}
|
| 682 |
+
.gradio-container h1 {{
|
| 683 |
+
background: linear-gradient(90deg, #F1FAEE 0%, #00D4FF 100%);
|
| 684 |
+
-webkit-background-clip: text;
|
| 685 |
+
-webkit-text-fill-color: transparent;
|
| 686 |
+
background-clip: text;
|
| 687 |
+
font-weight: 800 !important;
|
| 688 |
+
letter-spacing: -0.5px;
|
| 689 |
+
}}
|
| 690 |
+
.gradio-container h2, .gradio-container h3 {{ color: #00D4FF !important; }}
|
| 691 |
+
.gradio-container p {{ color: #A8DADC !important; }}
|
| 692 |
+
|
| 693 |
+
/* === Block 卡片 === */
|
| 694 |
+
.gradio-container .block,
|
| 695 |
+
.gradio-container .form,
|
| 696 |
+
.gradio-container .gr-block,
|
| 697 |
+
.gradio-container .panel,
|
| 698 |
+
.gradio-container .gr-panel {{
|
| 699 |
+
background: rgba(27, 42, 78, 0.55) !important;
|
| 700 |
+
border: 1px solid rgba(0, 212, 255, 0.25) !important;
|
| 701 |
+
border-radius: 14px !important;
|
| 702 |
+
backdrop-filter: blur(6px);
|
| 703 |
+
}}
|
| 704 |
+
|
| 705 |
+
/* === 下拉選單 === */
|
| 706 |
+
.gradio-container select,
|
| 707 |
+
.gradio-container .gr-dropdown,
|
| 708 |
+
.gradio-container .wrap input,
|
| 709 |
+
.gradio-container .gr-input,
|
| 710 |
+
.gradio-container input[type="text"],
|
| 711 |
+
.gradio-container input[type="number"],
|
| 712 |
+
.gradio-container textarea {{
|
| 713 |
+
background: rgba(11, 20, 38, 0.65) !important;
|
| 714 |
+
color: #F1FAEE !important;
|
| 715 |
+
border: 1px solid rgba(0, 212, 255, 0.35) !important;
|
| 716 |
+
border-radius: 10px !important;
|
| 717 |
+
}}
|
| 718 |
+
|
| 719 |
+
/* Label */
|
| 720 |
+
.gradio-container label, .gradio-container .gr-label,
|
| 721 |
+
.gradio-container span.svelte-1gfkn6j {{
|
| 722 |
+
color: #00D4FF !important;
|
| 723 |
+
font-weight: 600 !important;
|
| 724 |
+
letter-spacing: 0.5px !important;
|
| 725 |
+
}}
|
| 726 |
+
|
| 727 |
+
/* === 主要按鈕(次要:清除對話)— 珊瑚紅→陽光金 === */
|
| 728 |
+
.gradio-container button.secondary,
|
| 729 |
+
.gradio-container button[variant="secondary"] {{
|
| 730 |
+
background: linear-gradient(135deg, #FF6B6B 0%, #FFB627 100%) !important;
|
| 731 |
+
color: #0B1426 !important;
|
| 732 |
+
font-weight: 700 !important;
|
| 733 |
+
border: 0 !important;
|
| 734 |
+
border-radius: 10px !important;
|
| 735 |
+
box-shadow: 0 4px 14px rgba(255, 107, 107, 0.25) !important;
|
| 736 |
+
}}
|
| 737 |
+
.gradio-container button.primary,
|
| 738 |
+
.gradio-container button[variant="primary"] {{
|
| 739 |
+
background: linear-gradient(135deg, #00D4FF 0%, #A663CC 100%) !important;
|
| 740 |
+
color: #0B1426 !important;
|
| 741 |
+
font-weight: 700 !important;
|
| 742 |
+
border: 0 !important;
|
| 743 |
+
border-radius: 10px !important;
|
| 744 |
+
box-shadow: 0 4px 14px rgba(0, 212, 255, 0.25) !important;
|
| 745 |
+
}}
|
| 746 |
+
.gradio-container button:hover {{ filter: brightness(1.1); transform: translateY(-1px); }}
|
| 747 |
+
|
| 748 |
+
/* === 聊天視窗 === */
|
| 749 |
+
.gradio-container .message,
|
| 750 |
+
.gradio-container .bot,
|
| 751 |
+
.gradio-container .user {{ border-radius: 14px !important; }}
|
| 752 |
+
.gradio-container .message.user, .gradio-container .user-row .message {{
|
| 753 |
+
background: linear-gradient(135deg, rgba(0, 212, 255, 0.18), rgba(37, 99, 235, 0.22)) !important;
|
| 754 |
+
border: 1px solid rgba(0, 212, 255, 0.3) !important;
|
| 755 |
+
}}
|
| 756 |
+
.gradio-container .message.bot, .gradio-container .bot-row .message {{
|
| 757 |
+
background: rgba(255, 182, 39, 0.06) !important;
|
| 758 |
+
border: 1px solid rgba(255, 182, 39, 0.22) !important;
|
| 759 |
+
}}
|
| 760 |
+
|
| 761 |
+
/* === 隱藏 footer === */
|
| 762 |
+
footer {{ display: none !important; }}
|
| 763 |
+
|
| 764 |
+
/* === 滾動條配色 === */
|
| 765 |
+
::-webkit-scrollbar {{ width: 10px; height: 10px; }}
|
| 766 |
+
::-webkit-scrollbar-track {{ background: rgba(11, 20, 38, 0.5); }}
|
| 767 |
+
::-webkit-scrollbar-thumb {{
|
| 768 |
+
background: linear-gradient(180deg, #00D4FF, #A663CC);
|
| 769 |
+
border-radius: 5px;
|
| 770 |
+
}}
|
| 771 |
"""
|
| 772 |
|
| 773 |
+
|
| 774 |
LATEX_DELIMS = [
|
| 775 |
{"left": "$$", "right": "$$", "display": True},
|
| 776 |
{"left": "$", "right": "$", "display": False},
|