Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,75 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
|
| 4 |
-
# --- 1. 主題配色設定 (
|
|
|
|
| 5 |
theme = gr.themes.Soft(
|
| 6 |
primary_hue="amber",
|
| 7 |
neutral_hue="zinc",
|
| 8 |
font=[gr.themes.GoogleFont("Playfair Display"), "ui-sans-serif", "sans-serif"],
|
| 9 |
).set(
|
| 10 |
-
body_background_fill="#0F0F0F",
|
| 11 |
-
block_background_fill="#1a1a1a",
|
| 12 |
-
block_border_width="0px",
|
| 13 |
-
block_shadow="0 4px 6px rgba(0,0,0,0.3)",
|
| 14 |
-
input_background_fill="#262626", # 輸入框背景
|
| 15 |
-
input_border_color="#444444",
|
| 16 |
input_border_width="1px",
|
| 17 |
-
body_text_color="#E0E0E0",
|
| 18 |
-
block_title_text_color="#d4af37",
|
| 19 |
-
button_primary_background_fill="linear-gradient(45deg, #d4af37, #AA8E4A)",
|
| 20 |
button_primary_text_color="#000000",
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# --- 2. 高階 CSS (
|
| 24 |
custom_css = """
|
| 25 |
/* 隱藏 footer */
|
| 26 |
footer {visibility: hidden}
|
| 27 |
|
| 28 |
-
/* 整體背景漸層
|
| 29 |
.gradio-container {
|
| 30 |
background: radial-gradient(circle at 50% 0%, #2a2a2a 0%, #0F0F0F 100%) !important;
|
| 31 |
}
|
| 32 |
|
| 33 |
-
/*
|
| 34 |
.block {
|
| 35 |
-
background: rgba(30, 30, 30, 0.
|
| 36 |
-
|
| 37 |
-
border: 1px solid rgba(212, 175, 55, 0.1); /* 極淡的金色邊框 */
|
| 38 |
border-radius: 12px !important;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
/*
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
border-radius: 8px !important;
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
/* 輸入框美化 */
|
| 54 |
input, textarea, .dropdown-trigger {
|
| 55 |
background-color: rgba(0, 0, 0, 0.3) !important;
|
| 56 |
border: 1px solid #444 !important;
|
| 57 |
-
transition: all 0.3s ease;
|
| 58 |
}
|
| 59 |
input:focus, .dropdown-trigger:focus-within {
|
| 60 |
-
border-color: #d4af37 !important;
|
| 61 |
-
box-shadow: 0 0 10px rgba(212, 175, 55, 0.2) !important;
|
| 62 |
}
|
| 63 |
|
| 64 |
/* 按鈕美化 */
|
|
@@ -68,7 +79,7 @@ button.primary {
|
|
| 68 |
transition: transform 0.2s;
|
| 69 |
}
|
| 70 |
button.primary:hover {
|
| 71 |
-
transform: scale(1.02);
|
| 72 |
box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
|
| 73 |
}
|
| 74 |
|
|
@@ -83,7 +94,7 @@ h3 {
|
|
| 83 |
}
|
| 84 |
"""
|
| 85 |
|
| 86 |
-
# ---
|
| 87 |
def get_date_options():
|
| 88 |
options = []
|
| 89 |
today = datetime.now()
|
|
@@ -94,7 +105,6 @@ def get_date_options():
|
|
| 94 |
options.append(date_str)
|
| 95 |
return options
|
| 96 |
|
| 97 |
-
# --- 核心邏輯:動態計算時段 ---
|
| 98 |
def update_time_slots(date_str):
|
| 99 |
if not date_str:
|
| 100 |
return gr.update(choices=[]), "請先選擇日期"
|
|
@@ -118,7 +128,6 @@ def update_time_slots(date_str):
|
|
| 118 |
|
| 119 |
return gr.update(choices=slots, value=slots[0] if slots else None), status_msg
|
| 120 |
|
| 121 |
-
# --- 模擬寫入資料 ---
|
| 122 |
def handle_booking(name, tel, date_str, time, pax):
|
| 123 |
if not name or not tel or not date_str or not time:
|
| 124 |
return "⚠️ 請完整填寫所有欄位"
|
|
@@ -140,8 +149,6 @@ def handle_booking(name, tel, date_str, time, pax):
|
|
| 140 |
# --- 介面佈局 ---
|
| 141 |
with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
| 142 |
|
| 143 |
-
# 這裡不放標題,因為您的 GitHub Pages 已經有標題了
|
| 144 |
-
|
| 145 |
with gr.Row():
|
| 146 |
with gr.Column(scale=1):
|
| 147 |
gr.Markdown("### 📅 預約資訊 Booking Info")
|
|
@@ -161,7 +168,7 @@ with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
|
| 161 |
status_box = gr.Markdown("請先選擇日期...", visible=True)
|
| 162 |
time_slot = gr.Dropdown(choices=[], label="可用時段 Available Time", interactive=True)
|
| 163 |
|
| 164 |
-
gr.HTML("<div style='height: 20px'></div>")
|
| 165 |
|
| 166 |
gr.Markdown("### 👤 聯絡人資料 Contact")
|
| 167 |
with gr.Group():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
|
| 4 |
+
# --- 1. 主題配色設定 (強化版) ---
|
| 5 |
+
# 我們在這邊直接設定好 Dropdown 的顏色,這樣就算 CSS 沒吃到,也不會變成白底白字
|
| 6 |
theme = gr.themes.Soft(
|
| 7 |
primary_hue="amber",
|
| 8 |
neutral_hue="zinc",
|
| 9 |
font=[gr.themes.GoogleFont("Playfair Display"), "ui-sans-serif", "sans-serif"],
|
| 10 |
).set(
|
| 11 |
+
body_background_fill="#0F0F0F",
|
| 12 |
+
block_background_fill="#1a1a1a",
|
| 13 |
+
block_border_width="0px",
|
| 14 |
+
block_shadow="0 4px 6px rgba(0,0,0,0.3)",
|
| 15 |
+
input_background_fill="#262626", # 輸入框背景 (包含 Dropdown 未展開時)
|
| 16 |
+
input_border_color="#444444",
|
| 17 |
input_border_width="1px",
|
| 18 |
+
body_text_color="#E0E0E0",
|
| 19 |
+
block_title_text_color="#d4af37",
|
| 20 |
+
button_primary_background_fill="linear-gradient(45deg, #d4af37, #AA8E4A)",
|
| 21 |
button_primary_text_color="#000000",
|
| 22 |
+
# 🌟 新增:強制設定 Dropdown 選單展開後的顏色
|
| 23 |
+
table_row_focus_background_fill="#d4af37",
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# --- 2. 高階 CSS (修正選單不顯示的問題) ---
|
| 27 |
custom_css = """
|
| 28 |
/* 隱藏 footer */
|
| 29 |
footer {visibility: hidden}
|
| 30 |
|
| 31 |
+
/* 整體背景漸層 */
|
| 32 |
.gradio-container {
|
| 33 |
background: radial-gradient(circle at 50% 0%, #2a2a2a 0%, #0F0F0F 100%) !important;
|
| 34 |
}
|
| 35 |
|
| 36 |
+
/* 區塊樣式 (移除了 backdrop-filter,因為它常會導致彈出選單被裁切或消失) */
|
| 37 |
.block {
|
| 38 |
+
background: rgba(30, 30, 30, 0.8) !important;
|
| 39 |
+
border: 1px solid rgba(212, 175, 55, 0.1);
|
|
|
|
| 40 |
border-radius: 12px !important;
|
| 41 |
}
|
| 42 |
|
| 43 |
+
/* 🌟 修正重點:Dropdown 選單容器 */
|
| 44 |
+
/* Gradio 4.x 的選單 class 通常是 .options 或 .wrap .options */
|
| 45 |
+
.options {
|
| 46 |
+
background-color: #262626 !important; /* 深灰背景 */
|
| 47 |
+
border: 1px solid #d4af37 !important; /* 金色邊框 */
|
| 48 |
border-radius: 8px !important;
|
| 49 |
+
z-index: 9999 !important; /* 🔥 確保浮在最上層 */
|
| 50 |
+
box-shadow: 0 10px 20px rgba(0,0,0,0.5) !important;
|
| 51 |
}
|
| 52 |
+
|
| 53 |
+
/* 選單內的選項文字 */
|
| 54 |
+
.item {
|
| 55 |
+
color: #E0E0E0 !important;
|
| 56 |
+
padding: 8px 12px !important;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* 滑鼠滑過選項 */
|
| 60 |
+
.item:hover, .item.selected {
|
| 61 |
+
background-color: #d4af37 !important; /* 金色背景 */
|
| 62 |
+
color: #000000 !important; /* 黑色文字 */
|
| 63 |
}
|
| 64 |
|
| 65 |
/* 輸入框美化 */
|
| 66 |
input, textarea, .dropdown-trigger {
|
| 67 |
background-color: rgba(0, 0, 0, 0.3) !important;
|
| 68 |
border: 1px solid #444 !important;
|
|
|
|
| 69 |
}
|
| 70 |
input:focus, .dropdown-trigger:focus-within {
|
| 71 |
+
border-color: #d4af37 !important;
|
| 72 |
+
box-shadow: 0 0 10px rgba(212, 175, 55, 0.2) !important;
|
| 73 |
}
|
| 74 |
|
| 75 |
/* 按鈕美化 */
|
|
|
|
| 79 |
transition: transform 0.2s;
|
| 80 |
}
|
| 81 |
button.primary:hover {
|
| 82 |
+
transform: scale(1.02);
|
| 83 |
box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
|
| 84 |
}
|
| 85 |
|
|
|
|
| 94 |
}
|
| 95 |
"""
|
| 96 |
|
| 97 |
+
# --- 核心邏輯 (保持不變) ---
|
| 98 |
def get_date_options():
|
| 99 |
options = []
|
| 100 |
today = datetime.now()
|
|
|
|
| 105 |
options.append(date_str)
|
| 106 |
return options
|
| 107 |
|
|
|
|
| 108 |
def update_time_slots(date_str):
|
| 109 |
if not date_str:
|
| 110 |
return gr.update(choices=[]), "請先選擇日期"
|
|
|
|
| 128 |
|
| 129 |
return gr.update(choices=slots, value=slots[0] if slots else None), status_msg
|
| 130 |
|
|
|
|
| 131 |
def handle_booking(name, tel, date_str, time, pax):
|
| 132 |
if not name or not tel or not date_str or not time:
|
| 133 |
return "⚠️ 請完整填寫所有欄位"
|
|
|
|
| 149 |
# --- 介面佈局 ---
|
| 150 |
with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
| 151 |
|
|
|
|
|
|
|
| 152 |
with gr.Row():
|
| 153 |
with gr.Column(scale=1):
|
| 154 |
gr.Markdown("### 📅 預約資訊 Booking Info")
|
|
|
|
| 168 |
status_box = gr.Markdown("請先選擇日期...", visible=True)
|
| 169 |
time_slot = gr.Dropdown(choices=[], label="可用時段 Available Time", interactive=True)
|
| 170 |
|
| 171 |
+
gr.HTML("<div style='height: 20px'></div>")
|
| 172 |
|
| 173 |
gr.Markdown("### 👤 聯絡人資料 Contact")
|
| 174 |
with gr.Group():
|