Rammohan0504 commited on
Commit
7f87d5a
·
verified ·
1 Parent(s): 38d896c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -112
app.py CHANGED
@@ -1,115 +1,119 @@
1
  import gradio as gr
 
 
 
2
 
3
- # Data Module
4
- menu_data = [
5
- {
6
- "name": "Veg Burger",
7
- "category": "VEGAN",
8
- "image": "https://upload.wikimedia.org/wikipedia/commons/6/6e/Veggie_burger.jpg",
9
- "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato."
10
- },
11
- {
12
- "name": "Chicken Biryani",
13
- "category": "HALAL",
14
- "image": "https://upload.wikimedia.org/wikipedia/commons/7/79/Chicken_Biryani.jpg",
15
- "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces."
16
- },
17
- {
18
- "name": "Paneer Butter Masala",
19
- "category": "VEGAN",
20
- "image": "https://upload.wikimedia.org/wikipedia/commons/3/3d/Paneer_Butter_Masala.jpg",
21
- "description": "Paneer cooked in a rich and creamy tomato-based gravy."
22
- },
23
- ]
24
-
25
- # HTML Rendering Module
26
- def render_dish_grid(category):
27
- filtered_dishes = [
28
- dish for dish in menu_data if category == "ALL" or dish["category"] == category
29
- ]
30
- html_content = "<div style='display: flex; flex-wrap: wrap; justify-content: center;'>"
31
- for dish in filtered_dishes:
32
- html_content += f"""
33
- <div style='margin: 10px; text-align: center; cursor: pointer; border: 1px solid #ddd;
34
- padding: 10px; border-radius: 10px; width: 200px; background-color: #f9f9f9;'
35
- onclick='selectDish("{dish['name']}")'>
36
- <img src='{dish['image']}' alt='{dish['name']}'
37
- style='width: 180px; height: 120px; object-fit: cover; border-radius: 10px;'>
38
- <h4 style='margin-top: 10px; font-size: 16px; color: #444;'>{dish['name']}</h4>
39
- </div>
40
- """
41
- html_content += "</div>"
42
- return html_content
43
-
44
- # Business Logic Module
45
- def get_dish_details(dish_name):
46
- for dish in menu_data:
47
- if dish["name"] == dish_name:
48
- return gr.update(visible=True), dish["image"], dish["name"], dish["description"]
49
- return gr.update(visible=False), "", "Dish Not Found", "No description available."
50
-
51
- def close_popup():
52
- return gr.update(visible=False)
53
-
54
- # Gradio App Module
55
- def create_app():
56
- with gr.Blocks() as demo:
57
- gr.HTML("<h1 style='text-align: center;'>🍛 Biryani Menu 🍛</h1>")
58
-
59
- # JavaScript for dish selection
60
- gr.HTML("""
61
- <script>
62
- function selectDish(dishName) {
63
- let input = document.querySelector('input[aria-label="selected_dish_name"]');
64
- if (input) {
65
- input.value = dishName;
66
- input.dispatchEvent(new Event('input', { bubbles: true }));
67
- }
68
- }
69
- </script>
70
- """)
71
-
72
- gr.Markdown("### Select a Category")
 
 
 
73
  with gr.Row():
74
- btn_all = gr.Button("ALL")
75
- btn_vegan = gr.Button("VEGAN")
76
- btn_halal = gr.Button("HALAL")
77
-
78
- gr.Markdown("### Available Dishes")
79
- dish_display = gr.HTML(value=render_dish_grid("ALL"))
80
-
81
- # Pop-up for dish details
82
- popup = gr.Group(visible=False)
83
- with popup:
84
- with gr.Row():
85
- dish_image = gr.Image()
86
- with gr.Column():
87
- dish_name = gr.Textbox(label="Dish Name", interactive=False)
88
- dish_description = gr.Textbox(label="Description", interactive=False)
89
- close_button = gr.Button("Close")
90
-
91
- # Hidden textbox to handle JavaScript -> Python communication
92
- selected_dish_name = gr.Textbox(visible=False)
93
- selected_dish_name.change(
94
- fn=get_dish_details,
95
- inputs=selected_dish_name,
96
- outputs=[popup, dish_image, dish_name, dish_description]
97
- )
98
-
99
- # Close button functionality
100
- close_button.click(fn=close_popup, outputs=popup)
101
-
102
- # Update category buttons
103
- def update_dish_grid(category):
104
- return gr.update(value=render_dish_grid(category))
105
-
106
- btn_all.click(fn=lambda: update_dish_grid("ALL"), outputs=dish_display)
107
- btn_vegan.click(fn=lambda: update_dish_grid("VEGAN"), outputs=dish_display)
108
- btn_halal.click(fn=lambda: update_dish_grid("HALAL"), outputs=dish_display)
109
-
110
- return demo
111
-
112
- # Main Execution
113
- if __name__ == "__main__":
114
- app = create_app()
115
- app.launch()
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import qrcode
4
+ import os
5
 
6
+ # Data storage (for prototyping; switch to Salesforce or database for production)
7
+ customer_data_path = "customer_data.xlsx"
8
+ order_data_path = "order_data.xlsx"
9
+
10
+ # Ensure data files exist
11
+ if not os.path.exists(customer_data_path):
12
+ pd.DataFrame(columns=["Name", "Email", "Phone", "Preferences", "Allergies"]).to_excel(customer_data_path, index=False)
13
+
14
+ if not os.path.exists(order_data_path):
15
+ pd.DataFrame(columns=["Table", "Customer", "Order", "Status"]).to_excel(order_data_path, index=False)
16
+
17
+ # Sample menu (can be dynamically loaded from an external file)
18
+ menu = {
19
+ "Bread": ["Roti", "Naan", "Paratha"],
20
+ "Veg Curries": ["Paneer Butter Masala", "Mix Veg", "Dal Tadka"],
21
+ "Non-Veg Curries": ["Chicken Curry", "Mutton Korma", "Fish Curry"],
22
+ "Biryanis": ["Veg Biryani", "Chicken Biryani", "Mutton Biryani"]
23
+ }
24
+
25
+ # Generate QR Code for each table
26
+ def generate_qr(table_number):
27
+ qr = qrcode.make(f"https://your-huggingface-space/{table_number}")
28
+ qr_path = f"table_{table_number}_qr.png"
29
+ qr.save(qr_path)
30
+ return qr_path
31
+
32
+ # Sign-Up functionality
33
+ def sign_up(name, email, phone, preferences, allergies):
34
+ customer_data = pd.read_excel(customer_data_path)
35
+ if email in customer_data["Email"].values:
36
+ return "Email already exists! Please log in."
37
+ new_entry = {"Name": name, "Email": email, "Phone": phone, "Preferences": preferences, "Allergies": allergies}
38
+ customer_data = customer_data.append(new_entry, ignore_index=True)
39
+ customer_data.to_excel(customer_data_path, index=False)
40
+ return "Sign-Up successful! Please log in."
41
+
42
+ # Login functionality
43
+ def login(email):
44
+ customer_data = pd.read_excel(customer_data_path)
45
+ if email in customer_data["Email"].values:
46
+ customer = customer_data[customer_data["Email"] == email].iloc[0]
47
+ return f"Welcome back, {customer['Name']}!", customer.to_dict()
48
+ return "Email not found! Please sign up.", None
49
+
50
+ # Display menu based on preferences
51
+ def display_menu(preferences, allergies):
52
+ filtered_menu = {}
53
+ for category, items in menu.items():
54
+ filtered_menu[category] = [item for item in items if item not in allergies]
55
+ return filtered_menu
56
+
57
+ # Add item to order
58
+ def add_to_order(table, customer, item):
59
+ order_data = pd.read_excel(order_data_path)
60
+ new_order = {"Table": table, "Customer": customer, "Order": item, "Status": "Pending"}
61
+ order_data = order_data.append(new_order, ignore_index=True)
62
+ order_data.to_excel(order_data_path, index=False)
63
+ return "Item added to order."
64
+
65
+ # Gradio Interface
66
+ with gr.Blocks() as app:
67
+ gr.Markdown("# QR-Based Restaurant Ordering System")
68
+
69
+ # QR Code Section
70
+ with gr.Tab("Generate QR Code"):
71
+ table_input = gr.Number(label="Table Number", value=1)
72
+ qr_output = gr.Image(label="QR Code")
73
+ generate_button = gr.Button("Generate QR Code")
74
+
75
+ generate_button.click(generate_qr, inputs=table_input, outputs=qr_output)
76
+
77
+ # Sign-Up and Login Section
78
+ with gr.Tab("Sign Up / Login"):
79
  with gr.Row():
80
+ with gr.Column():
81
+ gr.Markdown("### Sign Up")
82
+ name_input = gr.Textbox(label="Name")
83
+ email_input = gr.Textbox(label="Email")
84
+ phone_input = gr.Textbox(label="Phone")
85
+ preferences_input = gr.Textbox(label="Preferences (e.g., Vegetarian)")
86
+ allergies_input = gr.Textbox(label="Allergies (e.g., Peanuts)")
87
+ sign_up_button = gr.Button("Sign Up")
88
+ sign_up_output = gr.Textbox(label="Sign-Up Status")
89
+
90
+ sign_up_button.click(sign_up,
91
+ inputs=[name_input, email_input, phone_input, preferences_input, allergies_input],
92
+ outputs=sign_up_output)
93
+
94
+ with gr.Column():
95
+ gr.Markdown("### Login")
96
+ login_email_input = gr.Textbox(label="Email")
97
+ login_button = gr.Button("Login")
98
+ login_output = gr.Textbox(label="Login Status")
99
+
100
+ login_button.click(login, inputs=login_email_input, outputs=login_output)
101
+
102
+ # Menu and Ordering Section
103
+ with gr.Tab("Menu & Order"):
104
+ preferences_input = gr.Textbox(label="Preferences (from Login)", interactive=False)
105
+ allergies_input = gr.Textbox(label="Allergies (from Login)", interactive=False)
106
+ menu_display = gr.JSON(label="Filtered Menu")
107
+ display_menu_button = gr.Button("Show Menu")
108
+
109
+ display_menu_button.click(display_menu, inputs=[preferences_input, allergies_input], outputs=menu_display)
110
+
111
+ item_input = gr.Textbox(label="Item to Add")
112
+ table_input = gr.Number(label="Table Number", value=1)
113
+ customer_input = gr.Textbox(label="Customer Name")
114
+ add_order_button = gr.Button("Add to Order")
115
+ add_order_output = gr.Textbox(label="Order Status")
116
+
117
+ add_order_button.click(add_to_order, inputs=[table_input, customer_input, item_input], outputs=add_order_output)
118
+
119
+ app.launch()