DeepLearning101 commited on
Commit
d43a0d9
·
verified ·
1 Parent(s): 4bfed4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -46
app.py CHANGED
@@ -1,7 +1,7 @@
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",
@@ -18,14 +18,38 @@ theme = gr.themes.Soft(
18
  button_primary_text_color="#000000",
19
  )
20
 
21
- # --- 自定義 CSS ---
22
  custom_css = """
 
23
  footer {visibility: hidden}
24
- .header-box { text-align: center; padding: 30px 0; margin-bottom: 20px; border-bottom: 1px solid #d4af37; }
25
- .header-title { font-family: 'Playfair Display', serif; font-size: 42px; color: #d4af37; letter-spacing: 3px; margin: 0; }
26
- .header-subtitle { font-family: sans-serif; color: #888; font-size: 14px; margin-top: 10px; letter-spacing: 1px; }
27
- /* 強制讓下拉選單的選項背景也是深色 (避免展開時變白) */
28
- .wrap { background-color: #262626 !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  """
30
 
31
  # --- 核心邏輯:產生未來 30 天的日期選項 ---
@@ -46,29 +70,25 @@ def update_time_slots(date_str):
46
  if not date_str:
47
  return gr.update(choices=[]), "請先選擇日期"
48
 
49
- # 解析日期字串,例如 "2026-01-16 (五)" -> 找出星期幾
50
- # 我們可以直接看括號裡的字,或是重新 parse 日期,這裡用 parse 比較穩
51
  try:
52
- clean_date_str = date_str.split(" ")[0] # 拿掉後面的 (五)
53
  date_obj = datetime.strptime(clean_date_str, "%Y-%m-%d")
54
- weekday = date_obj.weekday() # 0=週一, ... 4=週五, 5=週六
55
  except:
56
  return gr.update(choices=[]), "日期格式錯誤"
57
 
58
- # 基礎時段 (每天都有)
59
  slots = ["18:00", "18:30", "19:00", "19:30", "20:00", "20:30",
60
  "21:00", "21:30", "22:00", "22:30", "23:00", "23:30",
61
  "00:00", "00:30", "01:00"]
62
 
63
- # 判斷營業時間
64
  if weekday == 4 or weekday == 5:
65
- # --- 週五 (4) 與 週六 (5) ---
66
  slots.extend(["01:30", "02:00", "02:30"])
67
- status_msg = f"📅 選擇了 {date_str} (週末時段 營業至 03:00)"
68
  else:
69
- # --- 週日 到 週四 ---
70
  slots.extend(["01:30"])
71
- status_msg = f"📅 選擇了 {date_str} (平日時段 營業至 02:00)"
72
 
73
  return gr.update(choices=slots, value=slots[0] if slots else None), status_msg
74
 
@@ -78,69 +98,60 @@ def handle_booking(name, tel, date_str, time, pax):
78
  return "⚠️ 請完整填寫所有欄位"
79
 
80
  return f"""
81
- <div style='background: #2a2a2a; padding: 20px; border-left: 3px solid #d4af37; color: #fff;'>
82
- <h3 style='color: #d4af37; margin:0;'>🥂 預約申請已提交</h3>
83
- <ul style='color: #ccc; list-style: none; padding: 0;'>
84
- <li>日期:{date_str}</li>
85
- <li>時間:{time}</li>
86
- <li>人數:{pax} 位</li>
87
- <li>貴賓:{name} ({tel})</li>
88
- </ul>
89
- <p style='font-size: 0.9em; color: #888;'>系統將發送確認信至您的信箱,請留意查收。</p>
90
  </div>
91
  """
92
 
93
  # --- 介面佈局 ---
94
- with gr.Blocks(theme=theme, css=custom_css, title="Cié Cié Taipei") as demo:
 
 
 
95
 
96
- gr.HTML("""
97
- <div class="header-box">
98
- <h1 class="header-title">Cié Cié Taipei</h1>
99
- <p class="header-subtitle">URBAN LOUNGE & DINING</p>
100
- </div>
101
- """)
102
-
103
  with gr.Row():
104
  with gr.Column(scale=1):
105
  gr.Markdown("### 📅 預約資訊")
106
 
107
- # 🌟 修正重點:改用 Dropdown,並預先填入未來 30 天的選項
108
  date_options = get_date_options()
 
109
  booking_date = gr.Dropdown(
110
  choices=date_options,
111
- label="選擇日期 (未來 30 天)",
112
- value=date_options[0] if date_options else None,
113
- interactive=True
 
114
  )
115
 
116
- pax_count = gr.Slider(minimum=1, maximum=10, value=2, step=1, label="用餐人數",
117
- info="超過 10 人請直接來電")
118
 
119
  with gr.Column(scale=1):
120
  gr.Markdown("### 🕰️ 選擇時段")
121
- status_box = gr.Markdown("請選擇日期以查看剩餘座位")
122
  time_slot = gr.Dropdown(choices=[], label="可用時段", interactive=True)
123
 
124
  gr.Markdown("### 👤 聯絡人資料")
125
  with gr.Group():
126
  with gr.Row():
127
  cust_name = gr.Textbox(label="訂位姓名", placeholder="ex. 王小明")
128
- cust_tel = gr.Textbox(label="手機號碼", placeholder="ex. 0912-345-678")
129
 
 
 
 
130
  submit_btn = gr.Button("確認預約 Request Booking", size="lg", variant="primary")
131
  output_msg = gr.HTML(label="系統訊息")
132
 
133
  # --- 互動邏輯 ---
134
- # 當「日期選單」改變時,觸發更新
135
  booking_date.change(
136
  fn=update_time_slots,
137
  inputs=booking_date,
138
  outputs=[time_slot, status_box]
139
  )
140
 
141
- # 頁面載入時,自動觸發一次 (讓時段選單有預設值)
142
- demo.load(fn=update_time_slots, inputs=booking_date, outputs=[time_slot, status_box])
143
-
144
  submit_btn.click(
145
  handle_booking,
146
  inputs=[cust_name, cust_tel, booking_date, time_slot, pax_count],
 
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",
 
18
  button_primary_text_color="#000000",
19
  )
20
 
21
+ # --- 自定義 CSS (修正下拉選單看不見的問題) ---
22
  custom_css = """
23
+ /* 隱藏 footer */
24
  footer {visibility: hidden}
25
+
26
+ /* 針對 Dropdown 下拉選單的 "彈出層" 做強制顏色修正 */
27
+ ul.options {
28
+ background-color: #262626 !important; /* 選單背景改深灰 */
29
+ border: 1px solid #d4af37 !important; /* 邊框改金色 */
30
+ }
31
+
32
+ /* 選單內的每一個選項 */
33
+ li.item {
34
+ color: #E0E0E0 !important; /* 文字改灰白 */
35
+ }
36
+
37
+ /* 滑鼠滑過選項時的顏色 */
38
+ li.item:hover, li.item.selected {
39
+ background-color: #d4af37 !important; /* 背景變金 */
40
+ color: #000000 !important; /* 文字變黑 */
41
+ }
42
+
43
+ /* 修正輸入框內的文字顏色 */
44
+ .wrap .secondary-wrap input {
45
+ color: #E0E0E0 !important;
46
+ }
47
+
48
+ /* 移除 Gradio 預設的大片留白 */
49
+ .gradio-container {
50
+ padding-top: 0px !important;
51
+ margin-top: 0px !important;
52
+ }
53
  """
54
 
55
  # --- 核心邏輯:產生未來 30 天的日期選項 ---
 
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")
76
+ weekday = date_obj.weekday()
77
  except:
78
  return gr.update(choices=[]), "日期格式錯誤"
79
 
 
80
  slots = ["18:00", "18:30", "19:00", "19:30", "20:00", "20:30",
81
  "21:00", "21:30", "22:00", "22:30", "23:00", "23:30",
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
  return "⚠️ 請完整填寫所有欄位"
99
 
100
  return f"""
101
+ <div style='background: #2a2a2a; padding: 15px; border-radius: 5px; border: 1px solid #d4af37; color: #fff; text-align: center;'>
102
+ <h3 style='color: #d4af37; margin-bottom: 10px;'>🥂 預約申請已提交</h3>
103
+ <p style='font-size: 14px;'>{name} 貴賓 ({pax}位)<br>
104
+ {date_str} {time}</p>
105
+ <p style='font-size: 12px; color: #aaa; margin-top: 10px;'>確認信已發送至您的信箱</p>
 
 
 
 
106
  </div>
107
  """
108
 
109
  # --- 介面佈局 ---
110
+ # title 設為 None 可以隱藏瀏覽器分頁標題的預設顯示 (雖然嵌入後看不到)
111
+ with gr.Blocks(theme=theme, css=custom_css, title="Booking") as demo:
112
+
113
+ # ⚠️ 這裡已經移除了 header-box (標題區)
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
  fn=update_time_slots,
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],