Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# 1. Define your tables and their pixel coordinate boundaries (X_start, X_end, Y_start, Y_end)
|
| 4 |
+
# You will need to adjust these numbers based on your actual PNG layout dimensions!
|
| 5 |
+
TABLES_LAYOUT = {
|
| 6 |
+
"Table 1": {"x": (50, 180), "y": (50, 180)},
|
| 7 |
+
"Table 2": {"x": (220, 350), "y": (50, 180)},
|
| 8 |
+
"Table 3": {"x": (50, 180), "y": (250, 380)},
|
| 9 |
+
"Table 4": {"x": (220, 350), "y": (250, 380)},
|
| 10 |
+
"VIP Booth": {"x": (400, 600), "y": (100, 400)},
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
def handle_image_click(evt: gr.SelectData):
|
| 14 |
+
"""
|
| 15 |
+
This function triggers automatically whenever someone clicks the image.
|
| 16 |
+
evt.index contains a tuple: (X_coordinate, Y_coordinate)
|
| 17 |
+
"""
|
| 18 |
+
click_x, click_y = evt.index
|
| 19 |
+
|
| 20 |
+
# Check if the click coordinates fall inside any table's boundaries
|
| 21 |
+
for table_name, bounds in TABLES_LAYOUT.items():
|
| 22 |
+
x_min, x_max = bounds["x"]
|
| 23 |
+
y_min, y_max = bounds["y"]
|
| 24 |
+
|
| 25 |
+
if x_min <= click_x <= x_max and y_min <= click_y <= y_max:
|
| 26 |
+
return f"🎯 You successfully selected: **{table_name}**!"
|
| 27 |
+
|
| 28 |
+
return f"Clicked at (X: {click_x}, Y: {click_y}), but no table is located here. Please try clicking directly on a table."
|
| 29 |
+
|
| 30 |
+
# 2. Build the Gradio Interface
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# 🍽️ Restaurant Table Reservation Layout")
|
| 33 |
+
gr.Markdown("Click directly on a table in the floor plan image below to select it.")
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
# Display the floor plan PNG.
|
| 37 |
+
# Setting 'interactive=False' makes it clickable instead of an upload box.
|
| 38 |
+
floor_plan = gr.Image(
|
| 39 |
+
value="floor_layout.png", # Ensure this file is uploaded to your Space folder
|
| 40 |
+
label="Floor Plan Layout",
|
| 41 |
+
interactive=False
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
status_output = gr.Markdown("### Selection Status\nNo table selected yet.")
|
| 46 |
+
|
| 47 |
+
# Optional: A manual confirmation button or extra booking actions could go here
|
| 48 |
+
confirm_btn = gr.Button("Confirm Booking", variant="primary")
|
| 49 |
+
|
| 50 |
+
# 3. Bind the click event to our Python logic
|
| 51 |
+
floor_plan.select(fn=handle_image_click, inputs=None, outputs=status_output)
|
| 52 |
+
|
| 53 |
+
demo.launch()
|