Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,93 +3,79 @@ 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 |
spacing_size=gr.themes.sizes.spacing_md,
|
| 19 |
|
| 20 |
).set(
|
| 21 |
-
#
|
| 22 |
-
body_background_fill="#f8f9fa",
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 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 |
-
#
|
| 38 |
-
tabs_border_width="0px",
|
| 39 |
tabs_border_color="transparent",
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
button_secondary_background_fill="transparent",
|
| 43 |
-
button_secondary_background_fill_hover="rgba(0, 0, 0, 0.05)",
|
| 44 |
-
button_secondary_text_color="#6c757d",
|
| 45 |
-
button_secondary_text_color_hover="#005f73",
|
| 46 |
-
button_secondary_border_width="0px",
|
| 47 |
button_secondary_border_color="transparent",
|
| 48 |
-
button_secondary_radius="8px",
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 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 |
-
|
| 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 |
-
# ---
|
| 82 |
try:
|
| 83 |
count = get_and_update_visits()
|
| 84 |
-
visit_count_html = f"🚀
|
| 85 |
print(f"Application loaded. Total visits: {count}")
|
| 86 |
except Exception as e:
|
| 87 |
visit_count_html = "🚀 **總載入次數:** N/A"
|
| 88 |
print(f"Could not update visit count: {e}")
|
| 89 |
|
| 90 |
-
# ---
|
| 91 |
demo = create_ui(visit_count_html, theme=professional_theme)
|
| 92 |
|
| 93 |
-
# ---
|
| 94 |
if __name__ == "__main__":
|
| 95 |
demo.launch()
|
|
|
|
| 3 |
from core.visits import get_and_update_visits
|
| 4 |
from ui.layouts import create_ui
|
| 5 |
|
| 6 |
+
# --- Corrected theme definition ---
|
| 7 |
professional_theme = gr.themes.Soft(
|
| 8 |
+
# Set font
|
| 9 |
font=gr.themes.GoogleFont("Noto Sans TC"),
|
| 10 |
|
| 11 |
+
# Set color hues
|
| 12 |
+
primary_hue=gr.themes.colors.teal,
|
| 13 |
+
secondary_hue=gr.themes.colors.cyan,
|
| 14 |
+
neutral_hue="slate",
|
| 15 |
|
| 16 |
+
# Set component radius and spacing
|
| 17 |
radius_size=gr.themes.sizes.radius_md,
|
| 18 |
spacing_size=gr.themes.sizes.spacing_md,
|
| 19 |
|
| 20 |
).set(
|
| 21 |
+
# === Global Layout ===
|
| 22 |
+
body_background_fill="#f8f9fa",
|
| 23 |
+
panel_background_fill="#f8f9fa",
|
| 24 |
|
| 25 |
+
# === Block/Card Styling ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
block_background_fill="white",
|
| 27 |
+
block_border_width="0px",
|
| 28 |
+
block_border_color="transparent",
|
| 29 |
block_radius="16px",
|
| 30 |
+
block_shadow="0 4px 10px rgba(0, 0, 0, 0.08)",
|
| 31 |
|
| 32 |
+
# === Tab Styling ===
|
| 33 |
+
tabs_border_width="0px",
|
| 34 |
tabs_border_color="transparent",
|
| 35 |
|
| 36 |
+
# Unselected Tabs
|
| 37 |
+
button_secondary_background_fill="transparent",
|
| 38 |
+
button_secondary_background_fill_hover="rgba(0, 0, 0, 0.05)",
|
| 39 |
+
button_secondary_text_color="#6c757d",
|
| 40 |
+
button_secondary_text_color_hover="#005f73",
|
| 41 |
+
button_secondary_border_width="0px",
|
| 42 |
button_secondary_border_color="transparent",
|
| 43 |
+
button_secondary_radius="8px",
|
| 44 |
+
|
| 45 |
+
# --- ✨ CORRECTED: Removed the conflicting/repeated block for selected tabs ---
|
| 46 |
+
# The 'button_primary' styles below will now apply to BOTH selected tabs and primary buttons.
|
| 47 |
+
|
| 48 |
+
# === Primary Button Styling ===
|
| 49 |
+
button_primary_background_fill="#005f73",
|
| 50 |
+
button_primary_background_fill_hover="#0a9396",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
button_primary_text_color="white",
|
| 52 |
+
button_primary_radius="8px",
|
| 53 |
|
| 54 |
+
# === Input Textbox Styling ===
|
| 55 |
input_background_fill="white",
|
| 56 |
input_border_color="#dee2e6",
|
| 57 |
+
input_shadow="0 1px 3px rgba(0, 0, 0, 0.08)",
|
| 58 |
input_border_width="1.5px",
|
| 59 |
input_radius="8px",
|
| 60 |
|
| 61 |
+
# --- Other details ---
|
| 62 |
+
link_text_color="#0a9396",
|
| 63 |
link_text_color_hover="#005f73",
|
| 64 |
)
|
| 65 |
|
| 66 |
|
| 67 |
+
# --- Application startup logic (unchanged) ---
|
| 68 |
try:
|
| 69 |
count = get_and_update_visits()
|
| 70 |
+
visit_count_html = f"🚀 **總載-入次數:** {count}"
|
| 71 |
print(f"Application loaded. Total visits: {count}")
|
| 72 |
except Exception as e:
|
| 73 |
visit_count_html = "🚀 **總載入次數:** N/A"
|
| 74 |
print(f"Could not update visit count: {e}")
|
| 75 |
|
| 76 |
+
# --- Create UI with the corrected theme ---
|
| 77 |
demo = create_ui(visit_count_html, theme=professional_theme)
|
| 78 |
|
| 79 |
+
# --- Launch the application ---
|
| 80 |
if __name__ == "__main__":
|
| 81 |
demo.launch()
|