Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,48 +3,82 @@ import gradio as gr
|
|
| 3 |
from core.visits import get_and_update_visits
|
| 4 |
from ui.layouts import create_ui
|
| 5 |
|
| 6 |
-
# ---
|
| 7 |
professional_theme = gr.themes.Soft(
|
| 8 |
-
#
|
| 9 |
font=gr.themes.GoogleFont("Noto Sans TC"),
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
primary_hue=gr.themes.colors.teal,
|
| 13 |
-
secondary_hue=gr.themes.colors.cyan,
|
| 14 |
-
neutral_hue="slate",
|
| 15 |
|
| 16 |
-
#
|
| 17 |
radius_size=gr.themes.sizes.radius_md,
|
| 18 |
-
|
| 19 |
-
# ✨ CORRECTED: Replaced the string "20px" with a valid theme size object
|
| 20 |
spacing_size=gr.themes.sizes.spacing_md,
|
| 21 |
|
| 22 |
).set(
|
| 23 |
-
# ---
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
block_background_fill="white",
|
| 29 |
-
block_border_width="
|
| 30 |
-
block_border_color="
|
| 31 |
block_radius="16px",
|
| 32 |
-
block_shadow="0 4px
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
button_primary_text_color="white",
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
input_background_fill="white",
|
| 41 |
input_border_color="#dee2e6",
|
| 42 |
-
input_shadow="
|
| 43 |
input_border_width="1.5px",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
|
| 47 |
-
# ---
|
| 48 |
try:
|
| 49 |
count = get_and_update_visits()
|
| 50 |
visit_count_html = f"🚀 **總載入次數:** {count}"
|
|
@@ -53,10 +87,9 @@ except Exception as e:
|
|
| 53 |
visit_count_html = "🚀 **總載入次數:** N/A"
|
| 54 |
print(f"Could not update visit count: {e}")
|
| 55 |
|
| 56 |
-
# ---
|
| 57 |
demo = create_ui(visit_count_html, theme=professional_theme)
|
| 58 |
|
| 59 |
-
# ---
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
| 62 |
-
|
|
|
|
| 3 |
from core.visits import get_and_update_visits
|
| 4 |
from ui.layouts import create_ui
|
| 5 |
|
| 6 |
+
# --- 定義最終版的專業佈景主題 (大幅度調整) ---
|
| 7 |
professional_theme = gr.themes.Soft(
|
| 8 |
+
# 設定字體
|
| 9 |
font=gr.themes.GoogleFont("Noto Sans TC"),
|
| 10 |
|
| 11 |
+
# 設定色調
|
| 12 |
+
primary_hue=gr.themes.colors.teal, # 主要顏色 (藍綠)
|
| 13 |
+
secondary_hue=gr.themes.colors.cyan, # 次要顏色 (青色)
|
| 14 |
+
neutral_hue="slate", # 中性色調 (石板灰)
|
| 15 |
|
| 16 |
+
# 設定元件圓角與間距
|
| 17 |
radius_size=gr.themes.sizes.radius_md,
|
|
|
|
|
|
|
| 18 |
spacing_size=gr.themes.sizes.spacing_md,
|
| 19 |
|
| 20 |
).set(
|
| 21 |
+
# --- 全局佈局 ---
|
| 22 |
+
body_background_fill="#f8f9fa", # 淺灰色背景
|
| 23 |
+
|
| 24 |
+
# --- ✨ 新增: 隱藏 Gradio 預設的頂部應用標題和分享按鈕 ---
|
| 25 |
+
# 這樣我們就可以用 gr.Markdown 自行定義頂部標題
|
| 26 |
+
block_title_text_color="transparent", # 隱藏 Block 標題文字
|
| 27 |
+
block_title_background_fill="transparent", # 隱藏 Block 標題背景
|
| 28 |
+
panel_background_fill="#f8f9fa", # 確保頂部區域與 body 背景一致
|
| 29 |
|
| 30 |
+
# --- 卡片/區塊樣式 (與圖片中白色區塊一致) ---
|
| 31 |
block_background_fill="white",
|
| 32 |
+
block_border_width="0px", # 移除預設邊框
|
| 33 |
+
block_border_color="transparent", # 邊框顏色設為透明
|
| 34 |
block_radius="16px",
|
| 35 |
+
block_shadow="0 4px 10px rgba(0, 0, 0, 0.08)", # 更明顯的陰影,創造懸浮感
|
| 36 |
|
| 37 |
+
# --- Tab 樣式調整 (使其更像導覽列按鈕) ---
|
| 38 |
+
tabs_border_width="0px", # 移除 Tab 容器的邊框
|
| 39 |
+
tabs_border_color="transparent",
|
| 40 |
+
|
| 41 |
+
# 未選中的 Tab 標籤
|
| 42 |
+
button_secondary_background_fill="transparent", # 透明背景
|
| 43 |
+
button_secondary_background_fill_hover="rgba(0, 0, 0, 0.05)", # hover 時淺灰
|
| 44 |
+
button_secondary_text_color="#6c757d", # 次要文字色 (淺灰)
|
| 45 |
+
button_secondary_text_color_hover="#005f73", # hover 時主文字色
|
| 46 |
+
button_secondary_border_width="0px", # 移除邊框
|
| 47 |
+
button_secondary_border_color="transparent",
|
| 48 |
+
button_secondary_radius="8px", # 略微圓角
|
| 49 |
+
|
| 50 |
+
# 選中的 Tab 標籤 (活動狀態)
|
| 51 |
+
button_primary_background_fill="transparent", # 透明背景
|
| 52 |
+
button_primary_background_fill_hover="transparent",
|
| 53 |
+
button_primary_text_color="#005f73", # 主文字色
|
| 54 |
+
button_primary_border_width="0px",
|
| 55 |
+
button_primary_border_color="transparent",
|
| 56 |
+
button_primary_radius="8px",
|
| 57 |
+
# ✨ 新增: 在選中的 Tab 下方模擬一個高亮條
|
| 58 |
+
# 這部分需要透過 CSS 或 Gradio 的進階設定來達成,這裡先用文字顏色變化模擬
|
| 59 |
+
# 實際上需要更複雜的 `class_name` 和自訂 CSS 才能實現圖片中的下劃線效果
|
| 60 |
+
# 為了簡化,這裡主要透過顏色和背景來模擬視覺效果
|
| 61 |
+
|
| 62 |
+
# --- 按鈕樣式 (例如「執行程式碼」按鈕) ---
|
| 63 |
+
button_primary_background_fill="#005f73", # 深藍綠
|
| 64 |
+
button_primary_background_fill_hover="#0a9396", # 較亮的藍綠
|
| 65 |
button_primary_text_color="white",
|
| 66 |
+
button_primary_border_radius="8px",
|
| 67 |
|
| 68 |
+
# --- 輸入框樣式 ---
|
| 69 |
input_background_fill="white",
|
| 70 |
input_border_color="#dee2e6",
|
| 71 |
+
input_shadow="0 1px 3px rgba(0, 0, 0, 0.08)", # 較輕的陰影
|
| 72 |
input_border_width="1.5px",
|
| 73 |
+
input_radius="8px",
|
| 74 |
+
|
| 75 |
+
# --- 其他細節 ---
|
| 76 |
+
link_text_color="#0a9396", # 連結顏色
|
| 77 |
+
link_text_color_hover="#005f73",
|
| 78 |
)
|
| 79 |
|
| 80 |
|
| 81 |
+
# --- 2. 應用程式啟動邏輯 (維持不變) ---
|
| 82 |
try:
|
| 83 |
count = get_and_update_visits()
|
| 84 |
visit_count_html = f"🚀 **總載入次數:** {count}"
|
|
|
|
| 87 |
visit_count_html = "🚀 **總載入次數:** N/A"
|
| 88 |
print(f"Could not update visit count: {e}")
|
| 89 |
|
| 90 |
+
# --- 3. 建立 UI 並傳入佈景主題 ---
|
| 91 |
demo = create_ui(visit_count_html, theme=professional_theme)
|
| 92 |
|
| 93 |
+
# --- 4. 啟動應用程式 ---
|
| 94 |
if __name__ == "__main__":
|
| 95 |
demo.launch()
|
|
|