cwadayi commited on
Commit
8fa7399
·
verified ·
1 Parent(s): 4e2f039

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -46
app.py CHANGED
@@ -1,46 +1,68 @@
1
- # app.py
2
- import gradio as gr
3
- from core.visits import get_and_update_visits
4
- from ui.layouts import create_ui
5
-
6
- # --- 1. Define a new custom theme for better aesthetics ---
7
- custom_theme = gr.themes.Soft(
8
- primary_hue="blue",
9
- secondary_hue="cyan",
10
- neutral_hue="slate",
11
- spacing_size=gr.themes.sizes.spacing_md,
12
- radius_size=gr.themes.sizes.radius_md,
13
- ).set(
14
- # Custom colors
15
- body_background_fill="#F0F4F8",
16
- block_background_fill="white",
17
- block_border_width="1px",
18
- block_shadow="*shadow_drop_lg",
19
-
20
- # Custom button style
21
- button_primary_background_fill="*primary_500",
22
- button_primary_background_fill_hover="*primary_400",
23
- button_primary_text_color="white",
24
-
25
- # --- ADDED: Style for input textbox to make it more visible ---
26
- input_background_fill="white",
27
- input_border_color="*neutral_200",
28
- input_shadow="*shadow_drop",
29
- input_border_width="1.5px", # Slightly thicker border
30
- )
31
-
32
- # --- 2. Update site visit count on startup ---
33
- try:
34
- count = get_and_update_visits()
35
- visit_count_html = f"🚀 **總載入次數:** {count}"
36
- print(f"Application loaded. Total visits: {count}")
37
- except Exception as e:
38
- visit_count_html = "🚀 **總載入次數:** N/A"
39
- print(f"Could not update visit count: {e}")
40
-
41
- # --- 3. Create the main UI, passing both dynamic content and the new theme ---
42
- demo = create_ui(visit_count_html, theme=custom_theme)
43
-
44
- # --- 4. Launch the application ---
45
- if __name__ == "__main__":
46
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from core.visits import get_and_update_visits
4
+ from ui.layouts import create_ui
5
+
6
+ # --- 1. 全新定義一個更專業、更美觀的自訂主題 ---
7
+ # 參考您提供的網站設計語言 (顏色、字體、卡片式佈局)
8
+ professional_theme = gr.themes.Soft(
9
+ # 設定字體為 Noto Sans TC
10
+ font=gr.themes.GoogleFont("Noto Sans TC"),
11
+
12
+ # 參考網站的藍綠色系設定主色調
13
+ primary_hue=gr.themes.colors.teal,
14
+ secondary_hue=gr.themes.colors.cyan,
15
+ neutral_hue="slate",
16
+
17
+ # 調整元件的圓角大小,使其更現代
18
+ radius_size=gr.themes.sizes.radius_md,
19
+
20
+ ).set(
21
+ # === 整體佈局 ===
22
+ # 設定頁面背景色 (淺灰色,用以凸顯卡片)
23
+ body_background_fill="#f8f9fa",
24
+
25
+ # === 卡片/區塊樣式 (核心) ===
26
+ # 設定所有區塊 (如 Tab、Group) 的背景為純白
27
+ block_background_fill="white",
28
+ # 設定卡片的邊框
29
+ block_border_width="1px",
30
+ block_border_color="#dee2e6",
31
+ # 設定卡片的圓角
32
+ block_radius="16px",
33
+ # 設定卡片的陰影,創造懸浮感
34
+ block_shadow="0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.05)",
35
+
36
+ # === 按鈕樣式 ===
37
+ # 設定主按鈕的背景色 (深藍綠色)
38
+ button_primary_background_fill="#005f73",
39
+ button_primary_background_fill_hover="#0a9396",
40
+ button_primary_text_color="white",
41
+
42
+ # === 輸入框樣式 ===
43
+ input_background_fill="white",
44
+ input_border_color="#dee2e6",
45
+ input_shadow="*shadow_drop",
46
+ input_border_width="1.5px",
47
+
48
+ # === 間距 ===
49
+ spacing_size="20px", # 元件間的基礎間距
50
+ layout_gap="25px", # 區塊間的間距
51
+ )
52
+
53
+
54
+ # --- 2. 應用程式啟動邏輯 (維持不變) ---
55
+ try:
56
+ count = get_and_update_visits()
57
+ visit_count_html = f"🚀 **總載入次數:** {count}"
58
+ print(f"Application loaded. Total visits: {count}")
59
+ except Exception as e:
60
+ visit_count_html = "🚀 **總載入次數:** N/A"
61
+ print(f"Could not update visit count: {e}")
62
+
63
+ # --- 3. 建立 UI 時傳入新的佈景主題 ---
64
+ demo = create_ui(visit_count_html, theme=professional_theme)
65
+
66
+ # --- 4. 啟動應用程式 ---
67
+ if __name__ == "__main__":
68
+ demo.launch()