cwadayi commited on
Commit
a9e83d0
·
verified ·
1 Parent(s): 1b65622

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -53
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
- # --- 新增: 隱藏 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}"
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
- # --- 3. 建立 UI 並傳入佈景主題 ---
91
  demo = create_ui(visit_count_html, theme=professional_theme)
92
 
93
- # --- 4. 啟動應用程式 ---
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()