Spaces:
Running
Running
# app.py | |
import gradio as gr | |
from core.visits import get_and_update_visits | |
from ui.layouts import create_ui | |
# --- 最終版專業佈景主題 --- | |
professional_theme = gr.themes.Soft( | |
# 設定字體 | |
font=gr.themes.GoogleFont("Noto Sans TC"), | |
# 設定色調 | |
primary_hue=gr.themes.colors.teal, | |
secondary_hue=gr.themes.colors.cyan, | |
neutral_hue="slate", | |
# 設定元件圓角與間距 | |
radius_size=gr.themes.sizes.radius_md, | |
spacing_size=gr.themes.sizes.spacing_md, | |
).set( | |
# === 全局佈局 === | |
body_background_fill="#f8f9fa", | |
panel_background_fill="#f8f9fa", | |
# === 卡片/區塊樣式 === | |
block_background_fill="white", | |
block_border_width="0px", | |
block_border_color="transparent", | |
block_radius="16px", | |
block_shadow="0 4px 10px rgba(0, 0, 0, 0.08)", | |
# === 未選中分頁 (次要按鈕) 樣式 === | |
button_secondary_background_fill="transparent", | |
button_secondary_background_fill_hover="rgba(0, 0, 0, 0.05)", | |
button_secondary_text_color="#6c757d", | |
button_secondary_text_color_hover="#005f73", | |
# === 主要按鈕 (及選中分頁) 樣式 === | |
button_primary_background_fill="#005f73", | |
button_primary_background_fill_hover="#0a9396", | |
button_primary_text_color="white", | |
# === 輸入框樣式 === | |
input_background_fill="white", | |
input_border_color="#dee2e6", | |
input_shadow="0 1px 3px rgba(0, 0, 0, 0.08)", | |
input_border_width="1.5px", | |
input_radius="8px", | |
# --- 其他細節 --- | |
link_text_color="#0a9396", | |
link_text_color_hover="#005f73", | |
) | |
# --- 應用程式啟動邏輯 --- | |
try: | |
count = get_and_update_visits() | |
visit_count_html = f"🚀 **總載入次數:** {count}" | |
print(f"Application loaded. Total visits: {count}") | |
except Exception as e: | |
visit_count_html = "🚀 **總載入次數:** N/A" | |
print(f"Could not update visit count: {e}") | |
# --- 建立 UI 並傳入佈景主題 --- | |
demo = create_ui(visit_count_html, theme=professional_theme) | |
# --- 啟動應用程式 --- | |
if __name__ == "__main__": | |
demo.launch() | |