Rammohan0504 commited on
Commit
1e0171a
·
verified ·
1 Parent(s): aa7d8c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -46
app.py CHANGED
@@ -22,9 +22,7 @@ menu_data = [
22
 
23
 
24
 
25
- # Spice levels and extras
26
- spice_levels = ["American Mild", "American Medium", "American Spicy",
27
- "Indian Mild", "Indian Medium", "Indian Spicy", "Indian Very Spicy"]
28
  extras = [
29
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
30
  {"name": "Extra Raitha 8oz", "price": "$2.00"},
@@ -67,71 +65,78 @@ def display_dishes(category):
67
  html_content += "</div>"
68
  return html_content
69
 
70
- # Add to cart
71
- def add_to_cart(item_name, spice_level, extras_selected):
72
- cart.append({"name": item_name, "spice": spice_level, "extras": extras_selected})
73
- return "Item added to cart successfully!"
74
-
75
- # Display cart items
76
- def display_cart():
77
- if not cart:
78
- return "<p>Your cart is empty.</p>"
79
- html_content = "<div style='text-align: left;'>"
80
- for item in cart:
81
- html_content += f"<p><b>{item['name']}</b> - Spice: {item['spice']} - Extras: {', '.join(item['extras'])}</p>"
82
- html_content += "</div>"
83
- return html_content
84
 
85
  # Main Gradio App
86
  with gr.Blocks() as demo:
87
  gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
88
 
 
89
  with gr.Row():
90
  btn_all = gr.Button("ALL")
91
  btn_vegan = gr.Button("VEGAN")
92
  btn_halal = gr.Button("HALAL")
93
 
 
94
  dish_display = gr.HTML(value=display_dishes("ALL"))
95
- cart_display = gr.HTML(value=display_cart())
96
 
 
97
  gr.HTML(f"""
98
- <div id="popup" style="display: none;">
99
- <h2 id="popup-title"></h2>
100
- <label>Spice Level:</label>
101
- <select id="spice-select">""" + "".join([f'<option>{spice}</option>' for spice in spice_levels]) + """</select>
102
- <label>Extras:</label>
 
 
103
 
104
- html_content = '<div id="extras-select">'
105
- for extra in extras:
106
- html_content += f"<label><input type='checkbox' value='{extra['name']}'>{extra['name']} + {extra['price']}</label>"
107
- html_content += '</div>'
108
-
109
- gr.HTML(html_content)
110
 
 
 
 
 
111
 
112
- <button onclick="submitPopup()">Add to Cart</button>
113
- <button onclick="closePopup()">Close</button>
 
 
 
114
  </div>
115
  <script>
116
- function showPopup(name, price) {
117
- document.getElementById('popup-title').textContent = name;
 
 
 
 
 
118
  document.getElementById('popup').style.display = 'block';
119
  }
120
  function closePopup() {
121
  document.getElementById('popup').style.display = 'none';
122
  }
123
- function submitPopup() {
124
- const name = document.getElementById('popup-title').textContent;
125
- const spice = document.getElementById('spice-select').value;
126
- const extras = Array.from(document.querySelectorAll('#extras-select input:checked')).map(cb => cb.value);
127
- gr.Interface.postMessage('add_to_cart', [name, spice, extras]);
128
- closePopup();
129
  }
130
  </script>
131
- ")
132
-
133
- btn_all.click(lambda: gr.update(value=display_dishes("ALL")), outputs=dish_display)
134
- btn_vegan.click(lambda: gr.update(value=display_dishes("VEGAN")), outputs=dish_display)
135
- btn_halal.click(lambda: gr.update(value=display_dishes("HALAL")), outputs=dish_display)
136
-
137
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
22
 
23
 
24
 
25
+
 
 
26
  extras = [
27
  {"name": "Extra Raitha 4oz", "price": "$1.00"},
28
  {"name": "Extra Raitha 8oz", "price": "$2.00"},
 
65
  html_content += "</div>"
66
  return html_content
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  # Main Gradio App
70
  with gr.Blocks() as demo:
71
  gr.HTML("<h1 style='text-align: center; color: #333;'>🍛 Biryani Hub Menu 🍛</h1>")
72
 
73
+ # Buttons for category selection
74
  with gr.Row():
75
  btn_all = gr.Button("ALL")
76
  btn_vegan = gr.Button("VEGAN")
77
  btn_halal = gr.Button("HALAL")
78
 
79
+ # Dish display
80
  dish_display = gr.HTML(value=display_dishes("ALL"))
 
81
 
82
+ # JavaScript for managing the pop-up
83
  gr.HTML(f"""
84
+ <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
85
+ background-color: white; padding: 20px; border-radius: 10px;
86
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
87
+ <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
88
+ <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
89
+ <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
90
+ <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
91
 
92
+ <h4 style="text-align: left; margin-top: 20px;">Choose a spice level</h4>
93
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
94
+ """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="radio" name="spice" value="{spice}" style="margin-right: 5px;">{spice}</label>' for spice in spice_levels]) + """
95
+ </div>
 
 
96
 
97
+ <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
98
+ <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
99
+ """ + "".join([f'<label style="margin-right: 10px; display: block;"><input type="checkbox" name="extras" value="{extra["name"]}" style="margin-right: 5px;">{extra["name"]} + {extra["price"]}</label>' for extra in extras]) + """
100
+ </div>
101
 
102
+ <button onclick="addToCart(document.getElementById('popup-title').textContent, document.querySelector('input[name=spice]:checked').value)"
103
+ style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
104
+ border-radius: 5px; cursor: pointer;">Add to Cart</button>
105
+ <button onclick="closePopup()" style="margin-top: 20px; padding: 10px 20px; background-color: #28a745;
106
+ color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
107
  </div>
108
  <script>
109
+ function showPopup(image, title, description, price) {
110
+ document.getElementById('popup-image').src = image;
111
+ document.getElementById('popup-title').textContent = title;
112
+ document.getElementById('popup-description').textContent = description;
113
+ document.getElementById('popup-price').textContent = "Price: " + price;
114
+
115
+ // Display the popup
116
  document.getElementById('popup').style.display = 'block';
117
  }
118
  function closePopup() {
119
  document.getElementById('popup').style.display = 'none';
120
  }
121
+ function addToCart(dishName, spiceLevel) {
122
+ const selectedExtras = Array.from(document.querySelectorAll('input[name=extras]:checked')).map(cb => cb.value).join(", ");
123
+ alert(dishName + " with " + spiceLevel + " spice level and extras: " + selectedExtras + " has been added to the cart!");
 
 
 
124
  }
125
  </script>
126
+ """)
127
+
128
+ # Button click events
129
+ btn_all.click(
130
+ lambda: gr.update(value=display_dishes("ALL")),
131
+ outputs=dish_display
132
+ )
133
+ btn_vegan.click(
134
+ lambda: gr.update(value=display_dishes("VEGAN")),
135
+ outputs=dish_display
136
+ )
137
+ btn_halal.click(
138
+ lambda: gr.update(value=display_dishes("HALAL")),
139
+ outputs=dish_display
140
+ )
141
+
142
+ demo.launch()