Rammohan0504 commited on
Commit
5c2ec7c
·
verified ·
1 Parent(s): a0690bf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pyzbar.pyzbar as pyzbar
3
+ import cv2
4
+ import webbrowser
5
+
6
+ # Simulated menu data from the provided image
7
+ menu_data = {
8
+ "Vegan": [
9
+ {"name": "Vegetable Kurma", "description": "A creamy vegan vegetable curry.", "price": "$15"},
10
+ {"name": "Mixed Veg Chettinad", "description": "Spicy South Indian mixed vegetables.", "price": "$15"},
11
+ ],
12
+ "Halal": [
13
+ {"name": "Murgh (Chicken)", "description": "Tender chicken cooked with Indian spices.", "price": "$15"},
14
+ {"name": "Gosht (Goat)", "description": "Flavorful goat curry.", "price": "$16"},
15
+ ],
16
+ "Allergen-Free": [
17
+ {"name": "Shrimp Curry", "description": "Gluten-free shrimp curry cooked in coconut.", "price": "$17"},
18
+ {"name": "Fish Fry", "description": "Grilled fish without nuts or dairy.", "price": "$16"},
19
+ ],
20
+ "All": [
21
+ {"name": "Paneer Butter Masala", "description": "Paneer cooked in rich tomato gravy.", "price": "$16"},
22
+ {"name": "Chicken Biryani", "description": "Fragrant rice with tender halal chicken.", "price": "$17"},
23
+ ],
24
+ }
25
+
26
+ # QR Code Scanner Function
27
+ def scan_qr_code(image):
28
+ decoded_objects = pyzbar.decode(image)
29
+ if decoded_objects:
30
+ for obj in decoded_objects:
31
+ qr_data = obj.data.decode('utf-8')
32
+ webbrowser.open(qr_data) # Open menu link in browser
33
+ return f"QR Code scanned successfully! Redirecting to: {qr_data}"
34
+ return "No QR Code found. Please try again."
35
+
36
+ # Menu Filter Function
37
+ def display_menu(filter_option, spice_level, portion_size):
38
+ filtered_menu = menu_data.get(filter_option, [])
39
+ menu_display = ""
40
+ for item in filtered_menu:
41
+ menu_display += (
42
+ f"**{item['name']}**\n{item['description']}\nPrice: {item['price']}\n"
43
+ f"Spice Level: {spice_level} | Portion Size: {portion_size}\n\n"
44
+ )
45
+ return menu_display if menu_display else "No items found for this filter."
46
+
47
+ # Order Function
48
+ def place_order(item_name, spice_level, portion_size, special_instructions):
49
+ order_confirmation = (
50
+ f"Order Confirmed:\n- Item: {item_name}\n- Spice Level: {spice_level}\n"
51
+ f"- Portion Size: {portion_size}\n- Special Instructions: {special_instructions}"
52
+ )
53
+ return order_confirmation
54
+
55
+ # Gradio Interface
56
+ with gr.Blocks() as qr_menu_app:
57
+ gr.Markdown("## QR Code Ordering: Seamless and Contactless Dining")
58
+
59
+ # Section 1: QR Code Scanner
60
+ gr.Markdown("### 1. Scan the QR Code")
61
+ with gr.Row():
62
+ qr_input = gr.Image(type="numpy", label="Upload QR Code Image or Scan with Camera")
63
+ qr_output = gr.Textbox(label="QR Code Result")
64
+ qr_button = gr.Button("Scan QR Code")
65
+ qr_button.click(scan_qr_code, inputs=qr_input, outputs=qr_output)
66
+
67
+ # Section 2: Menu Filtering
68
+ gr.Markdown("### 2. Select Menu Preferences")
69
+ with gr.Row():
70
+ filter_option = gr.Dropdown(["Vegan", "Halal", "Allergen-Free", "All"], label="Filter Options")
71
+ spice_level = gr.Dropdown(["Mild", "Medium", "Spicy"], label="Spice Level")
72
+ portion_size = gr.Dropdown(["Small", "Medium", "Large"], label="Portion Size")
73
+ menu_output = gr.Textbox(label="Filtered Menu")
74
+ menu_button = gr.Button("Show Menu")
75
+ menu_button.click(display_menu, inputs=[filter_option, spice_level, portion_size], outputs=menu_output)
76
+
77
+ # Section 3: Place Order
78
+ gr.Markdown("### 3. Place Your Order")
79
+ with gr.Row():
80
+ order_item = gr.Textbox(label="Enter Item Name")
81
+ special_instructions = gr.Textbox(label="Special Instructions (Optional)")
82
+ order_output = gr.Textbox(label="Order Confirmation")
83
+ order_button = gr.Button("Place Order")
84
+ order_button.click(place_order, inputs=[order_item, spice_level, portion_size, special_instructions], outputs=order_output)
85
+
86
+ # Launch the Gradio App
87
+ qr_menu_app.launch()