Rammohan0504 commited on
Commit
059f34f
ยท
verified ยท
1 Parent(s): 4a94f34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -80
app.py CHANGED
@@ -1,90 +1,106 @@
1
  import gradio as gr
2
-
3
- # Extended menu data with dish details
4
- menu_data = [
5
- {"name": "Veg Burger", "category": "VEGAN",
6
- "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
7
- "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato."},
8
- {"name": "Chicken Biryani", "category": "HALAL",
9
- "image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
10
- "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces."},
11
- {"name": "Paneer Butter Masala", "category": "VEGAN",
12
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
13
- "description": "Paneer cooked in a rich and creamy tomato-based gravy."},
14
- {"name": "Beef Steak", "category": "HALAL",
15
- "image": "https://upload.wikimedia.org/wikipedia/commons/d/d5/Beef_Steak.jpg",
16
- "description": "Juicy beef steak served with mashed potatoes and grilled vegetables."},
17
- {"name": "Mushroom Soup", "category": "VEGAN",
18
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3c/Mushroom_Soup.jpg",
19
- "description": "Creamy mushroom soup with fresh herbs."}
20
- ]
21
-
22
- spice_options = ["๐ŸŒถ Mild", "๐ŸŒถ๐ŸŒถ Medium", "๐ŸŒถ๐ŸŒถ๐ŸŒถ High"]
23
- portion_options = ["๐Ÿง† Small", "๐Ÿฝ Medium", "๐Ÿ› Large"]
24
-
25
- # Function to filter dishes by category
26
- def get_dish_list(category):
27
- if category == "ALL":
28
- return [dish["name"] for dish in menu_data]
29
- return [dish["name"] for dish in menu_data if dish["category"] == category]
30
-
31
- # Function to fetch dish details
32
- def get_dish_details(dish_name):
33
- for dish in menu_data:
34
- if dish["name"] == dish_name:
35
- return dish["image"], dish["name"], dish["description"]
36
- return "https://via.placeholder.com/300x200", "Unknown Dish", "No description available."
37
-
38
- # Function to confirm order
39
- def place_order(dish_name, spice_level, portion_size):
40
- if dish_name:
41
- return f"โœ… Order Confirmed: '{dish_name}' with {spice_level} spice level and {portion_size} portion size."
42
- return "โš ๏ธ Please select a dish before placing an order."
43
-
44
- # Main Gradio App
45
- def gradio_app():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  with gr.Blocks() as demo:
47
- gr.HTML("<h1 style='text-align: center;'>๐Ÿ› Biryani Hub Menu ๐Ÿ›</h1>")
48
-
49
- # Category Selection
50
- gr.Markdown("### Select a Category")
51
- category_dropdown = gr.Radio(choices=["ALL", "VEGAN", "HALAL"], label="Categories", value="ALL")
52
 
53
- # Dish Selection
54
- gr.Markdown("### Select a Dish")
55
- dish_selector = gr.Radio(label="Available Dishes", choices=get_dish_list("ALL"))
56
-
57
- # Dish Details Section
58
- gr.Markdown("### Dish Details")
59
  with gr.Row():
60
- dish_image = gr.Image(label="Dish Image", height=200, width=200)
61
- with gr.Column():
62
- dish_name = gr.Textbox(label="Dish Name", interactive=False)
63
- dish_description = gr.Textbox(label="Description", interactive=False)
64
- spice_dropdown = gr.Radio(label="Select Spice Level", choices=spice_options, value="๐ŸŒถ Medium")
65
- portion_dropdown = gr.Radio(label="Select Portion Size", choices=portion_options, value="๐Ÿฝ Medium")
66
- place_order_btn = gr.Button("Place Order")
67
- order_status = gr.Textbox(label="Order Status", interactive=False)
68
-
69
- # Update dish list dynamically
70
- def update_dish_list(category):
71
- return gr.update(choices=get_dish_list(category))
72
 
73
- category_dropdown.change(fn=update_dish_list, inputs=category_dropdown, outputs=dish_selector)
 
 
 
 
 
74
 
75
- # Update dish details dynamically
76
- def update_dish_details(dish_name_input):
77
- return get_dish_details(dish_name_input)
 
 
 
78
 
79
- dish_selector.change(fn=update_dish_details, inputs=dish_selector,
80
- outputs=[dish_image, dish_name, dish_description])
 
 
 
 
81
 
82
- # Place order functionality
83
- place_order_btn.click(fn=place_order,
84
- inputs=[dish_name, spice_dropdown, portion_dropdown],
85
- outputs=order_status)
 
 
 
86
 
87
- return demo
88
 
89
- # Launch the app
90
- gradio_app().launch()
 
1
  import gradio as gr
2
+ import qrcode
3
+ from PIL import Image
4
+
5
+ # Sample Data
6
+ CUSTOMERS = {"9876543210": {"name": "John Doe", "preferences": ["Halal", "Indian"]}}
7
+ MENU = {
8
+ "ALL": [
9
+ {"name": "Chicken Curry", "description": "Spicy chicken curry", "image": "chicken_curry.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]},
10
+ {"name": "Paneer Butter Masala", "description": "Creamy paneer dish", "image": "paneer_butter.jpg", "spice_levels": ["Mild", "Medium", "Hot"], "portion_sizes": ["Small", "Medium", "Large"]}
11
+ ],
12
+ "VEGAN": [
13
+ {"name": "Veg Biryani", "description": "Flavourful veg biryani", "image": "veg_biryani.jpg", "spice_levels": ["Mild", "Medium"], "portion_sizes": ["Small", "Medium", "Large"]}
14
+ ]
15
+ }
16
+
17
+ # Generate QR Code
18
+
19
+ def generate_qr(table_id):
20
+ qr = qrcode.QRCode(box_size=10, border=5)
21
+ qr.add_data(f"http://restaurant.com/table/{table_id}")
22
+ qr.make(fit=True)
23
+ img = qr.make_image(fill="black", back_color="white")
24
+ return img
25
+
26
+ # Login / Signup
27
+
28
+ def login_or_signup(phone_number):
29
+ if phone_number in CUSTOMERS:
30
+ return f"Welcome back, {CUSTOMERS[phone_number]['name']}!", True
31
+ else:
32
+ return "Please sign up to continue.", False
33
+
34
+ # Save Preferences
35
+
36
+ def save_preferences(phone_number, preferences):
37
+ if phone_number not in CUSTOMERS:
38
+ return "Customer not found. Sign up first."
39
+ CUSTOMERS[phone_number]["preferences"] = preferences
40
+ return f"Preferences saved: {preferences}"
41
+
42
+ # Filter Menu
43
+
44
+ def filter_menu(preferences):
45
+ filtered_menu = MENU.get(preferences[0].upper(), MENU["ALL"])
46
+ return filtered_menu
47
+
48
+ # Dish Details
49
+
50
+ def dish_details(dish_name):
51
+ for category in MENU.values():
52
+ for dish in category:
53
+ if dish["name"] == dish_name:
54
+ return {
55
+ "Name": dish["name"],
56
+ "Description": dish["description"],
57
+ "Spice Levels": dish["spice_levels"],
58
+ "Portion Sizes": dish["portion_sizes"]
59
+ }, dish["image"]
60
+
61
+ # Gradio Interfaces
62
+
63
+ def main():
64
  with gr.Blocks() as demo:
65
+ gr.Markdown("# Restaurant QR Code Ordering System")
 
 
 
 
66
 
67
+ # QR Code Generator
 
 
 
 
 
68
  with gr.Row():
69
+ table_id = gr.Textbox(label="Table ID", placeholder="Enter table ID")
70
+ qr_button = gr.Button("Generate QR Code")
71
+ qr_output = gr.Image(label="QR Code")
72
+ qr_button.click(lambda table_id: generate_qr(table_id), inputs=table_id, outputs=qr_output)
 
 
 
 
 
 
 
 
73
 
74
+ # Login or Signup
75
+ with gr.Row():
76
+ phone_input = gr.Textbox(label="Phone Number", placeholder="Enter phone number")
77
+ login_button = gr.Button("Login / Signup")
78
+ login_output = gr.Text(label="Login Status")
79
+ login_button.click(login_or_signup, inputs=phone_input, outputs=login_output)
80
 
81
+ # Preferences
82
+ with gr.Row():
83
+ preferences = gr.CheckboxGroup(["Vegan", "Halal", "Indian", "Chinese"], label="Preferences")
84
+ pref_button = gr.Button("Save Preferences")
85
+ pref_output = gr.Text(label="Preference Status")
86
+ pref_button.click(save_preferences, inputs=[phone_input, preferences], outputs=pref_output)
87
 
88
+ # Menu Display
89
+ with gr.Row():
90
+ menu_pref = gr.Dropdown(["ALL", "VEGAN", "HALAL"], label="Menu Type")
91
+ menu_button = gr.Button("Show Menu")
92
+ menu_output = gr.JSON(label="Menu")
93
+ menu_button.click(filter_menu, inputs=menu_pref, outputs=menu_output)
94
 
95
+ # Dish Details
96
+ with gr.Row():
97
+ dish_name = gr.Textbox(label="Dish Name", placeholder="Enter dish name")
98
+ dish_button = gr.Button("Get Dish Details")
99
+ dish_output = gr.JSON(label="Dish Details")
100
+ dish_image = gr.Image(label="Dish Image")
101
+ dish_button.click(dish_details, inputs=dish_name, outputs=[dish_output, dish_image])
102
 
103
+ demo.launch()
104
 
105
+ if __name__ == "__main__":
106
+ main()