Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import secrets
|
| 3 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# ============================
|
| 6 |
# Procelevate Branding (UI)
|
|
@@ -42,7 +46,6 @@ a, .procelevate-accent {{
|
|
| 42 |
# ----------------------------
|
| 43 |
# In-memory stores (prototype)
|
| 44 |
# ----------------------------
|
| 45 |
-
# Sample "bookings database"
|
| 46 |
BOOKINGS = [
|
| 47 |
{
|
| 48 |
"booking_ref": "RZQ12345",
|
|
@@ -99,6 +102,19 @@ def _now():
|
|
| 99 |
return datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 100 |
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
# ----------------------------
|
| 103 |
# Core actions
|
| 104 |
# ----------------------------
|
|
@@ -142,9 +158,11 @@ def complete_checkin(mode, booking_state, arrival_time, bed_pref, special_reques
|
|
| 142 |
id_file: uploaded file (optional). OCR not included in v1.
|
| 143 |
"""
|
| 144 |
if not booking_state:
|
| 145 |
-
return "β Please verify your booking first.", "", gr.update(visible=False)
|
| 146 |
|
| 147 |
code = _generate_code("RZQ")
|
|
|
|
|
|
|
| 148 |
record = {
|
| 149 |
"code": code,
|
| 150 |
"mode": mode,
|
|
@@ -166,7 +184,7 @@ def complete_checkin(mode, booking_state, arrival_time, bed_pref, special_reques
|
|
| 166 |
f"β
{mode} Check-In Successful\n\n"
|
| 167 |
f"Your Express Check-In Code:\n{code}\n\n"
|
| 168 |
"Next step:\n"
|
| 169 |
-
"β’ Show this code at the front desk for quick room key collection.\n"
|
| 170 |
"β’ Estimated counter time: under 1 minute.\n\n"
|
| 171 |
"Thank you β we look forward to welcoming you."
|
| 172 |
)
|
|
@@ -186,7 +204,7 @@ def complete_checkin(mode, booking_state, arrival_time, bed_pref, special_reques
|
|
| 186 |
f"Submitted At: {record['created_at']}\n"
|
| 187 |
)
|
| 188 |
|
| 189 |
-
return guest_msg, staff_view, gr.update(visible=True)
|
| 190 |
|
| 191 |
|
| 192 |
def staff_lookup(code):
|
|
@@ -222,6 +240,7 @@ def reset_form():
|
|
| 222 |
"", "No preference", "", # arrival_time, bed_pref, special_request
|
| 223 |
None, # id_file
|
| 224 |
"", # guest_msg
|
|
|
|
| 225 |
"", # staff_preview
|
| 226 |
gr.update(visible=False), # staff_preview_container
|
| 227 |
)
|
|
@@ -235,7 +254,7 @@ with gr.Blocks(
|
|
| 235 |
css=CUSTOM_CSS
|
| 236 |
) as demo:
|
| 237 |
gr.Markdown(
|
| 238 |
-
|
| 239 |
# π¨ Smart Self Check-In (Prototype)
|
| 240 |
Complete your check-in in under **2 minutes** β **Pre-Arrival** or **On-Arrival**.
|
| 241 |
|
|
@@ -279,6 +298,7 @@ Step 1: Verify Booking β Step 2: Confirm Details β Step 3: Get Express C
|
|
| 279 |
|
| 280 |
gr.Markdown("### Step 3: Receive your Express Check-In Code")
|
| 281 |
guest_msg = gr.Textbox(label="Guest Confirmation", lines=7)
|
|
|
|
| 282 |
|
| 283 |
# Hide staff preview until submitted (looks more professional)
|
| 284 |
staff_preview_container = gr.Column(visible=False)
|
|
@@ -287,7 +307,6 @@ Step 1: Verify Booking β Step 2: Confirm Details β Step 3: Get Express C
|
|
| 287 |
|
| 288 |
reset_btn = gr.Button("Reset")
|
| 289 |
|
| 290 |
-
# Wiring
|
| 291 |
verify_btn.click(
|
| 292 |
verify_booking,
|
| 293 |
inputs=[booking_ref, last_name, checkin_date],
|
|
@@ -297,7 +316,7 @@ Step 1: Verify Booking β Step 2: Confirm Details β Step 3: Get Express C
|
|
| 297 |
submit_btn.click(
|
| 298 |
complete_checkin,
|
| 299 |
inputs=[mode, booking_state, arrival_time, bed_pref, special_request, id_file],
|
| 300 |
-
outputs=[guest_msg, staff_preview, staff_preview_container],
|
| 301 |
)
|
| 302 |
|
| 303 |
reset_btn.click(
|
|
@@ -307,7 +326,7 @@ Step 1: Verify Booking β Step 2: Confirm Details β Step 3: Get Express C
|
|
| 307 |
booking_ref, last_name, checkin_date,
|
| 308 |
verify_result, details_box, booking_state,
|
| 309 |
mode, arrival_time, bed_pref, special_request, id_file,
|
| 310 |
-
guest_msg, staff_preview, staff_preview_container
|
| 311 |
],
|
| 312 |
)
|
| 313 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import secrets
|
| 3 |
from datetime import datetime
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
+
import qrcode
|
| 7 |
+
from PIL import Image
|
| 8 |
|
| 9 |
# ============================
|
| 10 |
# Procelevate Branding (UI)
|
|
|
|
| 46 |
# ----------------------------
|
| 47 |
# In-memory stores (prototype)
|
| 48 |
# ----------------------------
|
|
|
|
| 49 |
BOOKINGS = [
|
| 50 |
{
|
| 51 |
"booking_ref": "RZQ12345",
|
|
|
|
| 102 |
return datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 103 |
|
| 104 |
|
| 105 |
+
def _qr_image_from_text(text: str) -> Image.Image:
|
| 106 |
+
qr = qrcode.QRCode(
|
| 107 |
+
version=1,
|
| 108 |
+
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
| 109 |
+
box_size=10,
|
| 110 |
+
border=2,
|
| 111 |
+
)
|
| 112 |
+
qr.add_data(text)
|
| 113 |
+
qr.make(fit=True)
|
| 114 |
+
img = qr.make_image(fill_color="black", back_color="white").convert("RGB")
|
| 115 |
+
return img
|
| 116 |
+
|
| 117 |
+
|
| 118 |
# ----------------------------
|
| 119 |
# Core actions
|
| 120 |
# ----------------------------
|
|
|
|
| 158 |
id_file: uploaded file (optional). OCR not included in v1.
|
| 159 |
"""
|
| 160 |
if not booking_state:
|
| 161 |
+
return "β Please verify your booking first.", None, "", gr.update(visible=False)
|
| 162 |
|
| 163 |
code = _generate_code("RZQ")
|
| 164 |
+
qr_img = _qr_image_from_text(code)
|
| 165 |
+
|
| 166 |
record = {
|
| 167 |
"code": code,
|
| 168 |
"mode": mode,
|
|
|
|
| 184 |
f"β
{mode} Check-In Successful\n\n"
|
| 185 |
f"Your Express Check-In Code:\n{code}\n\n"
|
| 186 |
"Next step:\n"
|
| 187 |
+
"β’ Show this code (or QR) at the front desk for quick room key collection.\n"
|
| 188 |
"β’ Estimated counter time: under 1 minute.\n\n"
|
| 189 |
"Thank you β we look forward to welcoming you."
|
| 190 |
)
|
|
|
|
| 204 |
f"Submitted At: {record['created_at']}\n"
|
| 205 |
)
|
| 206 |
|
| 207 |
+
return guest_msg, qr_img, staff_view, gr.update(visible=True)
|
| 208 |
|
| 209 |
|
| 210 |
def staff_lookup(code):
|
|
|
|
| 240 |
"", "No preference", "", # arrival_time, bed_pref, special_request
|
| 241 |
None, # id_file
|
| 242 |
"", # guest_msg
|
| 243 |
+
None, # qr_display
|
| 244 |
"", # staff_preview
|
| 245 |
gr.update(visible=False), # staff_preview_container
|
| 246 |
)
|
|
|
|
| 254 |
css=CUSTOM_CSS
|
| 255 |
) as demo:
|
| 256 |
gr.Markdown(
|
| 257 |
+
"""
|
| 258 |
# π¨ Smart Self Check-In (Prototype)
|
| 259 |
Complete your check-in in under **2 minutes** β **Pre-Arrival** or **On-Arrival**.
|
| 260 |
|
|
|
|
| 298 |
|
| 299 |
gr.Markdown("### Step 3: Receive your Express Check-In Code")
|
| 300 |
guest_msg = gr.Textbox(label="Guest Confirmation", lines=7)
|
| 301 |
+
qr_display = gr.Image(label="Express Check-In QR Code", type="pil", height=220)
|
| 302 |
|
| 303 |
# Hide staff preview until submitted (looks more professional)
|
| 304 |
staff_preview_container = gr.Column(visible=False)
|
|
|
|
| 307 |
|
| 308 |
reset_btn = gr.Button("Reset")
|
| 309 |
|
|
|
|
| 310 |
verify_btn.click(
|
| 311 |
verify_booking,
|
| 312 |
inputs=[booking_ref, last_name, checkin_date],
|
|
|
|
| 316 |
submit_btn.click(
|
| 317 |
complete_checkin,
|
| 318 |
inputs=[mode, booking_state, arrival_time, bed_pref, special_request, id_file],
|
| 319 |
+
outputs=[guest_msg, qr_display, staff_preview, staff_preview_container],
|
| 320 |
)
|
| 321 |
|
| 322 |
reset_btn.click(
|
|
|
|
| 326 |
booking_ref, last_name, checkin_date,
|
| 327 |
verify_result, details_box, booking_state,
|
| 328 |
mode, arrival_time, bed_pref, special_request, id_file,
|
| 329 |
+
guest_msg, qr_display, staff_preview, staff_preview_container
|
| 330 |
],
|
| 331 |
)
|
| 332 |
|