Rammohan0504 commited on
Commit
cb3331a
·
verified ·
1 Parent(s): 333829c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -104
app.py CHANGED
@@ -1,106 +1,80 @@
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()
 
1
  import gradio as gr
 
 
2
 
3
+ menu_data = [
4
+ {"name": "Veg Burger", "category": "VEGAN",
5
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/veg_burger.jpg",
6
+ "description": "A delicious vegan burger with plant-based patty, lettuce, and tomato."},
7
+ {"name": "Chicken Biryani", "category": "HALAL",
8
+ "image": "https://huggingface.co/spaces/Rammohan0504/dynamic_menu/resolve/main/images/chicken_biryani.jpg",
9
+ "description": "Spicy chicken biryani with aromatic basmati rice and tender chicken pieces."},
10
+ # Add more dishes here...
11
+ ]
12
+
13
+ # Filter menu based on category
14
+ def filter_dishes(category):
15
+ if category == "ALL":
16
+ return menu_data
17
+ return [dish for dish in menu_data if dish["category"] == category]
18
+
19
+ # Generate dish cards with JavaScript pop-up
20
+ def display_dishes(category):
21
+ filtered_dishes = filter_dishes(category)
22
+ html_content = "<div style='display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;'>"
23
+ for dish in filtered_dishes:
24
+ html_content += f"""
25
+ <div style='width: 300px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
26
+ background-color: #f9f9f9; text-align: center; cursor: pointer;'
27
+ onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
28
+ <img src='{dish['image']}' alt='{dish['name']}'
29
+ style='width: 100%; height: 150px; object-fit: cover; border-radius: 10px;'>
30
+ <h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
31
+ <p style='color: #666; font-size: 14px;'>{dish['description']}</p>
32
+ </div>
33
+ """
34
+ html_content += "</div>"
35
+ return html_content
36
+
37
+ # Main Gradio App
38
+ with gr.Blocks() as demo:
39
+ gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
40
+
41
+ # Buttons for category selection
42
+ with gr.Row():
43
+ btn_all = gr.Button("ALL")
44
+ btn_vegan = gr.Button("VEGAN")
45
+ btn_halal = gr.Button("HALAL")
46
+
47
+ # Dish display section
48
+ dish_display = gr.HTML(value=display_dishes("ALL"))
49
+
50
+ # Pop-up HTML and JavaScript
51
+ gr.HTML("""
52
+ <div id="popup" style="display: none; position: fixed; left: 50%; top: 10%; transform: translate(-50%, 0);
53
+ background-color: white; padding: 20px; border-radius: 10px;
54
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
55
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
56
+ <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
57
+ <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
58
+ <button onclick="closePopup()" style="margin-top: 10px; padding: 10px 20px; background-color: #28a745;
59
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
60
+ </div>
61
+ <script>
62
+ function showPopup(image, title, description) {
63
+ const popup = document.getElementById('popup');
64
+ document.getElementById('popup-image').src = image;
65
+ document.getElementById('popup-title').textContent = title;
66
+ document.getElementById('popup-description').textContent = description;
67
+ popup.style.display = 'block';
68
+ }
69
+ function closePopup() {
70
+ document.getElementById('popup').style.display = 'none';
71
+ }
72
+ </script>
73
+ """)
74
+
75
+ # Button click events for category filtering
76
+ btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
77
+ btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
78
+ btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
79
+
80
+ demo.launch()