Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,60 +1,127 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import datetime
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
custom_css = """
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"""
|
| 12 |
|
|
|
|
| 13 |
def get_available_slots(date_str):
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
return [("18:00", "剩 4 位"), ("19:30", "剩 2 位"), ("21:00", "已客滿")]
|
| 17 |
|
| 18 |
-
def handle_booking(name, tel,
|
| 19 |
if not name or not tel:
|
| 20 |
-
return "⚠️
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
gr.HTML("""
|
| 26 |
-
<div
|
| 27 |
-
<h1
|
| 28 |
-
<p
|
| 29 |
</div>
|
| 30 |
""")
|
| 31 |
-
|
|
|
|
| 32 |
with gr.Row():
|
|
|
|
| 33 |
with gr.Column(scale=1):
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
with gr.Column(scale=1):
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
with gr.Group():
|
| 43 |
-
gr.Markdown("### 4. 聯絡資訊")
|
| 44 |
with gr.Row():
|
| 45 |
-
cust_name = gr.Textbox(label="
|
| 46 |
-
cust_tel = gr.Textbox(label="
|
| 47 |
-
|
| 48 |
-
confirm_btn = gr.Button("探索味蕾之旅 (提交預約)", variant="primary")
|
| 49 |
-
result_output = gr.Markdown()
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
handle_booking,
|
| 56 |
-
inputs=[cust_name, cust_tel,
|
| 57 |
-
outputs=
|
| 58 |
)
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# --- 設定主題配色 (使用 Gradio 原生 Theme Builder) ---
|
| 4 |
+
# 我們選用 "Zinc" (冷灰) 作為基底,"Gold" (金) 作為強調色
|
| 5 |
+
theme = gr.themes.Soft(
|
| 6 |
+
primary_hue="amber", # 按鈕、強調色用琥珀金
|
| 7 |
+
neutral_hue="zinc", # 背景、邊框用鋅灰色 (比純黑更有質感)
|
| 8 |
+
font=[gr.themes.GoogleFont("Playfair Display"), "ui-sans-serif", "system-ui", "sans-serif"],
|
| 9 |
+
).set(
|
| 10 |
+
# 這裡微調細節,讓它看起來更像 "暗色模式"
|
| 11 |
+
body_background_fill="#1c1c1c", # 整體背景:深炭灰 (非純黑)
|
| 12 |
+
block_background_fill="#262626", # 區塊背景:稍亮一點的灰
|
| 13 |
+
block_border_width="0px", # 去掉生硬的邊框
|
| 14 |
+
input_background_fill="#333333", # 輸入框背景:深灰
|
| 15 |
+
input_border_color="#444444", # 輸入框邊框
|
| 16 |
+
text_color="#E0E0E0", # 一般文字:灰白 (不刺眼)
|
| 17 |
+
block_title_text_color="#d4af37", # 標題文字:香檳金
|
| 18 |
+
button_primary_background_fill="#d4af37", # 主按鈕背景:香檳金
|
| 19 |
+
button_primary_text_color="#000000", # 主按鈕文字:黑色
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# --- 自定義 CSS (只處理 Logo 和特殊排版) ---
|
| 23 |
custom_css = """
|
| 24 |
+
/* 隱藏 Gradio 預設的 footer */
|
| 25 |
+
footer {visibility: hidden}
|
| 26 |
+
|
| 27 |
+
/* 標題區域美化 */
|
| 28 |
+
.header-box {
|
| 29 |
+
text-align: center;
|
| 30 |
+
padding: 30px 0;
|
| 31 |
+
margin-bottom: 20px;
|
| 32 |
+
border-bottom: 1px solid #d4af37;
|
| 33 |
+
}
|
| 34 |
+
.header-title {
|
| 35 |
+
font-family: 'Playfair Display', serif;
|
| 36 |
+
font-size: 42px;
|
| 37 |
+
color: #d4af37; /* 香檳金 */
|
| 38 |
+
letter-spacing: 3px;
|
| 39 |
+
margin: 0;
|
| 40 |
+
}
|
| 41 |
+
.header-subtitle {
|
| 42 |
+
font-family: sans-serif;
|
| 43 |
+
color: #888;
|
| 44 |
+
font-size: 14px;
|
| 45 |
+
margin-top: 10px;
|
| 46 |
+
letter-spacing: 1px;
|
| 47 |
+
}
|
| 48 |
+
/* 讓日曆選單不要太亮 */
|
| 49 |
+
input[type="datetime-local"] {
|
| 50 |
+
color-scheme: dark;
|
| 51 |
+
}
|
| 52 |
"""
|
| 53 |
|
| 54 |
+
# --- 模擬資料與邏輯 ---
|
| 55 |
def get_available_slots(date_str):
|
| 56 |
+
# 這裡未來接 Supabase
|
| 57 |
+
return ["18:00 (剩 4 位)", "19:30 (剩 2 位)", "21:00 (已客滿)"]
|
|
|
|
| 58 |
|
| 59 |
+
def handle_booking(name, tel, date, time, pax):
|
| 60 |
if not name or not tel:
|
| 61 |
+
return "⚠️ 請完整填寫資料"
|
| 62 |
+
return f"""
|
| 63 |
+
<div style='background: #2a2a2a; padding: 20px; border-left: 3px solid #d4af37; color: #fff;'>
|
| 64 |
+
<h3 style='color: #d4af37; margin:0;'>🥂 預約申請已提交</h3>
|
| 65 |
+
<p>親愛的 <b>{name}</b>,我們已收到您的資訊。<br>
|
| 66 |
+
系統將發送確認信至您的信箱,請留意查收。</p>
|
| 67 |
+
</div>
|
| 68 |
+
"""
|
| 69 |
|
| 70 |
+
# --- 介面佈局 ---
|
| 71 |
+
with gr.Blocks(theme=theme, css=custom_css, title="Cié Cié Taipei") as demo:
|
| 72 |
+
|
| 73 |
+
# 1. 頂部 Logo 區
|
| 74 |
gr.HTML("""
|
| 75 |
+
<div class="header-box">
|
| 76 |
+
<h1 class="header-title">Cié Cié Taipei</h1>
|
| 77 |
+
<p class="header-subtitle">URBAN LOUNGE & DINING</p>
|
| 78 |
</div>
|
| 79 |
""")
|
| 80 |
+
|
| 81 |
+
# 2. 主要操作區 (分左右兩欄)
|
| 82 |
with gr.Row():
|
| 83 |
+
# 左側:選擇時間與人數
|
| 84 |
with gr.Column(scale=1):
|
| 85 |
+
gr.Markdown("### 📅 預約資訊")
|
| 86 |
+
# 日期改用 Textbox + type='date' 比較穩定,或者用 Dropdown
|
| 87 |
+
# 這裡暫用 Calendar,但在暗色模式下有些瀏覽器會顯示白色,這是瀏覽器限制
|
| 88 |
+
# 建議實務上也可以用 Dropdown 選「今天/明天/後天」
|
| 89 |
+
booking_date = gr.DateTime(label="日期與時間", include_time=False)
|
| 90 |
|
| 91 |
+
pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數",
|
| 92 |
+
info="超過 10 人請直接來電")
|
| 93 |
+
|
| 94 |
+
# 右側:時段與狀態
|
| 95 |
with gr.Column(scale=1):
|
| 96 |
+
gr.Markdown("### 🕰️ 選擇時段")
|
| 97 |
+
# 這裡用一個明顯的狀態顯示區
|
| 98 |
+
status_box = gr.Markdown("請選擇日期以查看剩餘座位", visible=True)
|
| 99 |
+
time_slot = gr.Dropdown(choices=[], label="可用時段", interactive=True)
|
| 100 |
+
|
| 101 |
+
# 3. 個人資料區
|
| 102 |
+
gr.Markdown("### 👤 聯絡人資料")
|
| 103 |
with gr.Group():
|
|
|
|
| 104 |
with gr.Row():
|
| 105 |
+
cust_name = gr.Textbox(label="訂位姓名", placeholder="ex. 王小明")
|
| 106 |
+
cust_tel = gr.Textbox(label="手機號碼", placeholder="ex. 0912-345-678")
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
# 4. 送出按鈕與結果
|
| 109 |
+
submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
|
| 110 |
+
output_msg = gr.HTML(label="系統訊息")
|
| 111 |
+
|
| 112 |
+
# --- 互動邏輯 ---
|
| 113 |
+
# 當日期改變,去查時段
|
| 114 |
+
booking_date.change(
|
| 115 |
+
fn=lambda d: (gr.update(choices=["18:00","18:30", "19:00","19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "00:00", "00:30", "01:00", "01:30", "02:00",]), "✅ 已更新時段"),
|
| 116 |
+
inputs=booking_date,
|
| 117 |
+
outputs=[time_slot, status_box]
|
| 118 |
+
)
|
| 119 |
|
| 120 |
+
submit_btn.click(
|
| 121 |
+
handle_booking,
|
| 122 |
+
inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count],
|
| 123 |
+
outputs=output_msg
|
| 124 |
)
|
| 125 |
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
demo.launch()
|