DeepLearning101 commited on
Commit
ccfb5f6
·
verified ·
1 Parent(s): 91b069f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -38
app.py CHANGED
@@ -1,60 +1,127 @@
1
  import gradio as gr
2
- import datetime
3
 
4
- # 自定義 CSS:打造高級黑金風格
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  custom_css = """
6
- .gradio-container { background-color: #0c0c0c !important; color: #d4af37 !important; }
7
- .gr-button-primary { background: linear-gradient(45deg, #af8f2c, #d4af37) !important; border: none !important; color: black !important; font-weight: bold !important; }
8
- .gr-input, .gr-dropdown, .gr-number { background-color: #1a1a1a !important; border: 1px solid #333 !important; color: white !important; }
9
- h1 { font-family: 'Playfair Display', serif; letter-spacing: 2px; }
10
- .availability-box { padding: 10px; border: 1px solid #d4af37; border-radius: 5px; text-align: center; margin-bottom: 20px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  """
12
 
 
13
  def get_available_slots(date_str):
14
- # 這裡未來會接 Supabase 查詢
15
- # 範例邏輯:如果是假日就剩比較少位子
16
- return [("18:00", "剩 4 位"), ("19:30", "剩 2 位"), ("21:00", "已客滿")]
17
 
18
- def handle_booking(name, tel, pax, date, time):
19
  if not name or not tel:
20
- return "⚠️ 請完整填寫姓名與聯絡電話。"
21
- # 這裡執行寫入 Supabase 的邏輯
22
- return f"### 🥂 預約申請已提交!\n**{name}** 您好,我們已收到您的申請。請留意 Email 並於 24 小時內點擊「確認出席」以保留您的座位。"
 
 
 
 
 
23
 
24
- with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
 
 
 
25
  gr.HTML("""
26
- <div style="text-align: center; padding: 20px;">
27
- <h1 style="font-size: 36px;">Cié Cié Taipei</h1>
28
- <p style="color: #888;">品味精緻時光,期待您的蒞臨</p>
29
  </div>
30
  """)
31
-
 
32
  with gr.Row():
 
33
  with gr.Column(scale=1):
34
- booking_date = gr.DateTime(label="1. 選擇日期", type="string")
35
- pax_count = gr.Slider(minimum=1, maximum=8, value=2, step=1, label="2. 用餐人數")
 
 
 
36
 
 
 
 
 
37
  with gr.Column(scale=1):
38
- # 這裡顯示即時剩餘座位狀態
39
- availability_display = gr.HTML("<div class='availability-box'>請先選擇日期以查看剩餘座位</div>")
40
- time_slot = gr.Dropdown(choices=["18:00", "19:30", "21:00"], label="3. 選擇時段")
41
-
 
 
 
42
  with gr.Group():
43
- gr.Markdown("### 4. 聯絡資訊")
44
  with gr.Row():
45
- cust_name = gr.Textbox(label="姓名", placeholder="請輸入訂位人姓名")
46
- cust_tel = gr.Textbox(label="電話", placeholder="請輸入手機號碼")
47
-
48
- confirm_btn = gr.Button("探索味蕾之旅 (提交預約)", variant="primary")
49
- result_output = gr.Markdown()
50
 
51
- # 當日期或人數改變時,動態更新顯示(互動性體驗)
52
- booking_date.change(lambda: "<div class='availability-box'>🔍 查詢中...</div>", outputs=availability_display)
 
 
 
 
 
 
 
 
 
53
 
54
- confirm_btn.click(
55
- handle_booking,
56
- inputs=[cust_name, cust_tel, pax_count, booking_date, time_slot],
57
- outputs=result_output
58
  )
59
 
60
- demo.launch()
 
 
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()