Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,85 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
|
| 4 |
-
# ---
|
| 5 |
theme = gr.themes.Soft(
|
| 6 |
primary_hue="amber",
|
| 7 |
neutral_hue="zinc",
|
| 8 |
-
font=[gr.themes.GoogleFont("Playfair Display"), "ui-sans-serif", "
|
| 9 |
).set(
|
| 10 |
-
body_background_fill="#
|
| 11 |
-
block_background_fill="#
|
| 12 |
-
block_border_width="0px",
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
-
# ---
|
| 22 |
custom_css = """
|
| 23 |
/* 隱藏 footer */
|
| 24 |
footer {visibility: hidden}
|
| 25 |
|
| 26 |
-
/*
|
| 27 |
-
|
| 28 |
-
background
|
| 29 |
-
border: 1px solid #d4af37 !important; /* 邊框改金色 */
|
| 30 |
}
|
| 31 |
|
| 32 |
-
/*
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
li.item:hover, li.item.selected {
|
| 39 |
-
background-color: #d4af37 !important;
|
| 40 |
-
color: #000000 !important;
|
| 41 |
}
|
| 42 |
|
| 43 |
-
/*
|
| 44 |
-
|
| 45 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
-
/*
|
| 49 |
-
.
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
"""
|
| 54 |
|
|
@@ -57,10 +88,8 @@ def get_date_options():
|
|
| 57 |
options = []
|
| 58 |
today = datetime.now()
|
| 59 |
weekdays = ["(一)", "(二)", "(三)", "(四)", "(五)", "(六)", "(日)"]
|
| 60 |
-
|
| 61 |
-
for i in range(30): # 開放未來 30 天
|
| 62 |
current_date = today + timedelta(days=i)
|
| 63 |
-
# 格式:2026-01-16 (五)
|
| 64 |
date_str = f"{current_date.strftime('%Y-%m-%d')} {weekdays[current_date.weekday()]}"
|
| 65 |
options.append(date_str)
|
| 66 |
return options
|
|
@@ -69,7 +98,6 @@ def get_date_options():
|
|
| 69 |
def update_time_slots(date_str):
|
| 70 |
if not date_str:
|
| 71 |
return gr.update(choices=[]), "請先選擇日期"
|
| 72 |
-
|
| 73 |
try:
|
| 74 |
clean_date_str = date_str.split(" ")[0]
|
| 75 |
date_obj = datetime.strptime(clean_date_str, "%Y-%m-%d")
|
|
@@ -82,13 +110,11 @@ def update_time_slots(date_str):
|
|
| 82 |
"00:00", "00:30", "01:00"]
|
| 83 |
|
| 84 |
if weekday == 4 or weekday == 5:
|
| 85 |
-
# 週五、六
|
| 86 |
slots.extend(["01:30", "02:00", "02:30"])
|
| 87 |
-
status_msg = f"已選擇 {date_str} (週末營業至 03:00)"
|
| 88 |
else:
|
| 89 |
-
# 平日
|
| 90 |
slots.extend(["01:30"])
|
| 91 |
-
status_msg = f"已選擇 {date_str} (平日營業至 02:00)"
|
| 92 |
|
| 93 |
return gr.update(choices=slots, value=slots[0] if slots else None), status_msg
|
| 94 |
|
|
@@ -98,65 +124,59 @@ def handle_booking(name, tel, date_str, time, pax):
|
|
| 98 |
return "⚠️ 請完整填寫所有欄位"
|
| 99 |
|
| 100 |
return f"""
|
| 101 |
-
<div style='background:
|
| 102 |
-
<
|
| 103 |
-
<p style='font-size:
|
| 104 |
-
|
| 105 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
| 107 |
"""
|
| 108 |
|
| 109 |
# --- 介面佈局 ---
|
| 110 |
-
# title 設為 None 可以隱藏瀏覽器分頁標題的預設顯示 (雖然嵌入後看不到)
|
| 111 |
with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
|
| 112 |
|
| 113 |
-
#
|
| 114 |
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column(scale=1):
|
| 117 |
-
gr.Markdown("### 📅 預約資訊")
|
| 118 |
|
| 119 |
date_options = get_date_options()
|
| 120 |
-
# value 設為 None,讓使用者必須主動選
|
| 121 |
booking_date = gr.Dropdown(
|
| 122 |
choices=date_options,
|
| 123 |
-
label="選擇日期",
|
| 124 |
value=None,
|
| 125 |
interactive=True,
|
| 126 |
-
info="開放未來 30 天預訂"
|
| 127 |
)
|
| 128 |
|
| 129 |
-
pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數")
|
| 130 |
|
| 131 |
with gr.Column(scale=1):
|
| 132 |
-
gr.Markdown("### 🕰️ 選擇時段")
|
| 133 |
status_box = gr.Markdown("請先選擇日期...", visible=True)
|
| 134 |
-
time_slot = gr.Dropdown(choices=[], label="可用時段", interactive=True)
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
gr.Markdown("### 👤 聯絡人資料")
|
| 137 |
with gr.Group():
|
| 138 |
with gr.Row():
|
| 139 |
-
cust_name = gr.Textbox(label="訂位姓名", placeholder="ex. 王小明")
|
| 140 |
-
cust_tel = gr.Textbox(label="手機號碼", placeholder="ex. 0912-xxx-xxx")
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
# 增加一點間距
|
| 143 |
-
gr.HTML("<div style='height: 10px'></div>")
|
| 144 |
-
|
| 145 |
submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
|
| 146 |
output_msg = gr.HTML(label="系統訊息")
|
| 147 |
|
| 148 |
# --- 互動邏輯 ---
|
| 149 |
-
booking_date.change(
|
| 150 |
-
|
| 151 |
-
inputs=booking_date,
|
| 152 |
-
outputs=[time_slot, status_box]
|
| 153 |
-
)
|
| 154 |
-
|
| 155 |
-
submit_btn.click(
|
| 156 |
-
handle_booking,
|
| 157 |
-
inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count],
|
| 158 |
-
outputs=output_msg
|
| 159 |
-
)
|
| 160 |
|
| 161 |
if __name__ == "__main__":
|
| 162 |
demo.launch()
|
|
|
|
| 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 |
+
/* 整體背景漸層 (營造 Lounge 氛圍) */
|
| 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.6) !important; /* 半透明深灰 */
|
| 36 |
+
backdrop-filter: blur(10px); /* 模糊背景 */
|
| 37 |
+
border: 1px solid rgba(212, 175, 55, 0.1); /* 極淡的金色邊框 */
|
| 38 |
+
border-radius: 12px !important;
|
| 39 |
}
|
| 40 |
|
| 41 |
+
/* 下拉選單修正 (黑底金字) */
|
| 42 |
+
ul.options {
|
| 43 |
+
background-color: #1a1a1a !important;
|
| 44 |
+
border: 1px solid #d4af37 !important;
|
| 45 |
+
border-radius: 8px !important;
|
| 46 |
+
}
|
| 47 |
+
li.item { color: #E0E0E0 !important; }
|
| 48 |
li.item:hover, li.item.selected {
|
| 49 |
+
background-color: #d4af37 !important;
|
| 50 |
+
color: #000000 !important;
|
| 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 |
+
/* 按鈕美化 */
|
| 65 |
+
button.primary {
|
| 66 |
+
font-weight: bold !important;
|
| 67 |
+
letter-spacing: 1px !important;
|
| 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 |
+
|
| 75 |
+
/* 標題美化 */
|
| 76 |
+
h3 {
|
| 77 |
+
font-family: 'Playfair Display', serif !important;
|
| 78 |
+
text-transform: uppercase;
|
| 79 |
+
letter-spacing: 2px;
|
| 80 |
+
border-bottom: 1px solid rgba(212, 175, 55, 0.3);
|
| 81 |
+
padding-bottom: 10px;
|
| 82 |
+
margin-bottom: 15px !important;
|
| 83 |
}
|
| 84 |
"""
|
| 85 |
|
|
|
|
| 88 |
options = []
|
| 89 |
today = datetime.now()
|
| 90 |
weekdays = ["(一)", "(二)", "(三)", "(四)", "(五)", "(六)", "(日)"]
|
| 91 |
+
for i in range(30):
|
|
|
|
| 92 |
current_date = today + timedelta(days=i)
|
|
|
|
| 93 |
date_str = f"{current_date.strftime('%Y-%m-%d')} {weekdays[current_date.weekday()]}"
|
| 94 |
options.append(date_str)
|
| 95 |
return options
|
|
|
|
| 98 |
def update_time_slots(date_str):
|
| 99 |
if not date_str:
|
| 100 |
return gr.update(choices=[]), "請先選擇日期"
|
|
|
|
| 101 |
try:
|
| 102 |
clean_date_str = date_str.split(" ")[0]
|
| 103 |
date_obj = datetime.strptime(clean_date_str, "%Y-%m-%d")
|
|
|
|
| 110 |
"00:00", "00:30", "01:00"]
|
| 111 |
|
| 112 |
if weekday == 4 or weekday == 5:
|
|
|
|
| 113 |
slots.extend(["01:30", "02:00", "02:30"])
|
| 114 |
+
status_msg = f"✨ 已選擇 {date_str} (週末營業至 03:00)"
|
| 115 |
else:
|
|
|
|
| 116 |
slots.extend(["01:30"])
|
| 117 |
+
status_msg = f"🌙 已選擇 {date_str} (平日營業至 02:00)"
|
| 118 |
|
| 119 |
return gr.update(choices=slots, value=slots[0] if slots else None), status_msg
|
| 120 |
|
|
|
|
| 124 |
return "⚠️ 請完整填寫所有欄位"
|
| 125 |
|
| 126 |
return f"""
|
| 127 |
+
<div style='background: rgba(42, 42, 42, 0.8); padding: 20px; border-radius: 10px; border: 1px solid #d4af37; color: #fff; text-align: center; box-shadow: 0 4px 15px rgba(0,0,0,0.5);'>
|
| 128 |
+
<h2 style='color: #d4af37; margin-bottom: 10px; font-family: Playfair Display;'>Request Confirmed</h2>
|
| 129 |
+
<p style='font-size: 16px; margin: 10px 0;'>🥂 預約申請已提交</p>
|
| 130 |
+
<hr style='border: 0; border-top: 1px solid #555; margin: 15px 0;'>
|
| 131 |
+
<div style='text-align: left; display: inline-block;'>
|
| 132 |
+
<p><b>👤 貴賓:</b> {name} ({pax}位)</p>
|
| 133 |
+
<p><b>📅 日期:</b> {date_str}</p>
|
| 134 |
+
<p><b>🕰️ 時間:</b> {time}</p>
|
| 135 |
+
</div>
|
| 136 |
+
<p style='font-size: 12px; color: #aaa; margin-top: 20px;'>系統將發送確認信至您的信箱,請留意查收。</p>
|
| 137 |
</div>
|
| 138 |
"""
|
| 139 |
|
| 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")
|
| 148 |
|
| 149 |
date_options = get_date_options()
|
|
|
|
| 150 |
booking_date = gr.Dropdown(
|
| 151 |
choices=date_options,
|
| 152 |
+
label="選擇日期 Select Date",
|
| 153 |
value=None,
|
| 154 |
interactive=True,
|
|
|
|
| 155 |
)
|
| 156 |
|
| 157 |
+
pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數 Guest Count")
|
| 158 |
|
| 159 |
with gr.Column(scale=1):
|
| 160 |
+
gr.Markdown("### 🕰️ 選擇時段 Time Slot")
|
| 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():
|
| 168 |
with gr.Row():
|
| 169 |
+
cust_name = gr.Textbox(label="訂位姓名 Name", placeholder="ex. 王小明")
|
| 170 |
+
cust_tel = gr.Textbox(label="手機號碼 Phone", placeholder="ex. 0912-xxx-xxx")
|
| 171 |
+
|
| 172 |
+
gr.HTML("<div style='height: 20px'></div>")
|
| 173 |
|
|
|
|
|
|
|
|
|
|
| 174 |
submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
|
| 175 |
output_msg = gr.HTML(label="系統訊息")
|
| 176 |
|
| 177 |
# --- 互動邏輯 ---
|
| 178 |
+
booking_date.change(update_time_slots, inputs=booking_date, outputs=[time_slot, status_box])
|
| 179 |
+
submit_btn.click(handle_booking, inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count], outputs=output_msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
if __name__ == "__main__":
|
| 182 |
demo.launch()
|