Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 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",
|
|
@@ -10,87 +9,54 @@ theme = gr.themes.Soft(
|
|
| 10 |
).set(
|
| 11 |
body_background_fill="#0F0F0F",
|
| 12 |
block_background_fill="#1a1a1a",
|
| 13 |
-
block_border_width="
|
| 14 |
-
|
| 15 |
-
input_background_fill="#262626",
|
| 16 |
-
input_border_color="#
|
| 17 |
-
input_border_width="1px",
|
| 18 |
body_text_color="#E0E0E0",
|
| 19 |
block_title_text_color="#d4af37",
|
| 20 |
-
button_primary_background_fill="
|
| 21 |
button_primary_text_color="#000000",
|
| 22 |
-
# 🌟 新增:強制設定 Dropdown 選單展開後的顏色
|
| 23 |
-
table_row_focus_background_fill="#d4af37",
|
| 24 |
)
|
| 25 |
|
| 26 |
-
# --- 2.
|
| 27 |
custom_css = """
|
| 28 |
/* 隱藏 footer */
|
| 29 |
-
footer {
|
| 30 |
|
| 31 |
-
/*
|
| 32 |
-
.gradio-container {
|
| 33 |
-
|
| 34 |
}
|
| 35 |
|
| 36 |
-
/*
|
| 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 |
-
|
| 49 |
-
|
| 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:
|
| 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
|
| 73 |
}
|
| 74 |
|
| 75 |
-
/*
|
| 76 |
-
button.primary {
|
| 77 |
-
font-weight: bold !important;
|
| 78 |
-
letter-spacing: 1px !important;
|
| 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 |
-
|
| 86 |
-
/* 標題美化 */
|
| 87 |
h3 {
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
border-bottom: 1px solid rgba(212, 175, 55, 0.3);
|
| 92 |
-
padding-bottom: 10px;
|
| 93 |
-
margin-bottom: 15px !important;
|
| 94 |
}
|
| 95 |
"""
|
| 96 |
|
|
@@ -133,42 +99,28 @@ def handle_booking(name, tel, date_str, time, pax):
|
|
| 133 |
return "⚠️ 請完整填寫所有欄位"
|
| 134 |
|
| 135 |
return f"""
|
| 136 |
-
<div style='
|
| 137 |
-
<h2 style='color: #d4af37; margin
|
| 138 |
-
<p style='
|
| 139 |
-
<
|
| 140 |
-
<div style='text-align: left; display: inline-block;'>
|
| 141 |
-
<p><b>👤 貴賓:</b> {name} ({pax}位)</p>
|
| 142 |
-
<p><b>📅 日期:</b> {date_str}</p>
|
| 143 |
-
<p><b>🕰️ 時間:</b> {time}</p>
|
| 144 |
-
</div>
|
| 145 |
-
<p style='font-size: 12px; color: #aaa; margin-top: 20px;'>系統將發送確認信至您的信箱,請留意查收。</p>
|
| 146 |
</div>
|
| 147 |
"""
|
| 148 |
|
| 149 |
# --- 介面佈局 ---
|
| 150 |
with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
| 151 |
-
|
| 152 |
with gr.Row():
|
| 153 |
-
with gr.Column(
|
| 154 |
gr.Markdown("### 📅 預約資訊 Booking Info")
|
| 155 |
-
|
| 156 |
date_options = get_date_options()
|
| 157 |
-
booking_date = gr.Dropdown(
|
| 158 |
-
choices=date_options,
|
| 159 |
-
label="選擇日期 Select Date",
|
| 160 |
-
value=None,
|
| 161 |
-
interactive=True,
|
| 162 |
-
)
|
| 163 |
-
|
| 164 |
pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數 Guest Count")
|
| 165 |
|
| 166 |
-
with gr.Column(
|
| 167 |
gr.Markdown("### 🕰️ 選擇時段 Time Slot")
|
| 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():
|
|
@@ -177,11 +129,9 @@ with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
|
| 177 |
cust_tel = gr.Textbox(label="手機號碼 Phone", placeholder="ex. 0912-xxx-xxx")
|
| 178 |
|
| 179 |
gr.HTML("<div style='height: 20px'></div>")
|
| 180 |
-
|
| 181 |
submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
|
| 182 |
output_msg = gr.HTML(label="系統訊息")
|
| 183 |
|
| 184 |
-
# --- 互動邏輯 ---
|
| 185 |
booking_date.change(update_time_slots, inputs=booking_date, outputs=[time_slot, status_box])
|
| 186 |
submit_btn.click(handle_booking, inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count], outputs=output_msg)
|
| 187 |
|
|
|
|
| 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",
|
|
|
|
| 9 |
).set(
|
| 10 |
body_background_fill="#0F0F0F",
|
| 11 |
block_background_fill="#1a1a1a",
|
| 12 |
+
block_border_width="1px",
|
| 13 |
+
block_border_color="#333",
|
| 14 |
+
input_background_fill="#262626",
|
| 15 |
+
input_border_color="#444",
|
|
|
|
| 16 |
body_text_color="#E0E0E0",
|
| 17 |
block_title_text_color="#d4af37",
|
| 18 |
+
button_primary_background_fill="#d4af37",
|
| 19 |
button_primary_text_color="#000000",
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
+
# --- 2. CSS 修復 (解決選單被擋住 + 樣式美化) ---
|
| 23 |
custom_css = """
|
| 24 |
/* 隱藏 footer */
|
| 25 |
+
footer {display: none !important;}
|
| 26 |
|
| 27 |
+
/* 強制讓所有容器允許內容溢出 (解決選單被裁切的關鍵) */
|
| 28 |
+
.gradio-container, .block, .row, .column {
|
| 29 |
+
overflow: visible !important;
|
| 30 |
}
|
| 31 |
|
| 32 |
+
/* 下拉選單樣式修正 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
.options {
|
| 34 |
+
background-color: #262626 !important;
|
| 35 |
+
border: 1px solid #d4af37 !important;
|
| 36 |
+
z-index: 10000 !important; /* 確保在最上層 */
|
| 37 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.5);
|
|
|
|
| 38 |
}
|
| 39 |
|
|
|
|
| 40 |
.item {
|
| 41 |
color: #E0E0E0 !important;
|
|
|
|
| 42 |
}
|
| 43 |
|
|
|
|
| 44 |
.item:hover, .item.selected {
|
| 45 |
+
background-color: #d4af37 !important;
|
| 46 |
+
color: black !important;
|
| 47 |
}
|
| 48 |
|
| 49 |
+
/* 輸入框聚焦時的金色光暈 */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
input:focus, .dropdown-trigger:focus-within {
|
| 51 |
border-color: #d4af37 !important;
|
| 52 |
+
box-shadow: 0 0 8px rgba(212, 175, 55, 0.4) !important;
|
| 53 |
}
|
| 54 |
|
| 55 |
+
/* 標題樣式 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
h3 {
|
| 57 |
+
border-bottom: 1px solid #444;
|
| 58 |
+
padding-bottom: 5px;
|
| 59 |
+
margin-bottom: 10px;
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
| 61 |
"""
|
| 62 |
|
|
|
|
| 99 |
return "⚠️ 請完整填寫所有欄位"
|
| 100 |
|
| 101 |
return f"""
|
| 102 |
+
<div style='text-align: center; color: #fff; padding: 20px; border: 1px solid #d4af37; border-radius: 8px; background: #222;'>
|
| 103 |
+
<h2 style='color: #d4af37; margin: 0;'>Request Received</h2>
|
| 104 |
+
<p style='margin: 10px 0;'>🥂 預約申請已提交</p>
|
| 105 |
+
<p style='font-size: 0.9em; color: #aaa;'>系統將發送確認信至您的信箱。</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
| 107 |
"""
|
| 108 |
|
| 109 |
# --- 介面佈局 ---
|
| 110 |
with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
|
|
|
| 111 |
with gr.Row():
|
| 112 |
+
with gr.Column():
|
| 113 |
gr.Markdown("### 📅 預約資訊 Booking Info")
|
|
|
|
| 114 |
date_options = get_date_options()
|
| 115 |
+
booking_date = gr.Dropdown(choices=date_options, label="選擇日期 Select Date", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數 Guest Count")
|
| 117 |
|
| 118 |
+
with gr.Column():
|
| 119 |
gr.Markdown("### 🕰️ 選擇時段 Time Slot")
|
| 120 |
status_box = gr.Markdown("請先選擇日期...", visible=True)
|
| 121 |
time_slot = gr.Dropdown(choices=[], label="可用時段 Available Time", interactive=True)
|
| 122 |
|
| 123 |
+
gr.HTML("<div style='height: 20px'></div>")
|
| 124 |
|
| 125 |
gr.Markdown("### 👤 聯絡人資料 Contact")
|
| 126 |
with gr.Group():
|
|
|
|
| 129 |
cust_tel = gr.Textbox(label="手機號碼 Phone", placeholder="ex. 0912-xxx-xxx")
|
| 130 |
|
| 131 |
gr.HTML("<div style='height: 20px'></div>")
|
|
|
|
| 132 |
submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
|
| 133 |
output_msg = gr.HTML(label="系統訊息")
|
| 134 |
|
|
|
|
| 135 |
booking_date.change(update_time_slots, inputs=booking_date, outputs=[time_slot, status_box])
|
| 136 |
submit_btn.click(handle_booking, inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count], outputs=output_msg)
|
| 137 |
|