Rammohan0504 commited on
Commit
a143b90
Β·
verified Β·
1 Parent(s): 41afd74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -76
app.py CHANGED
@@ -64,89 +64,74 @@ def display_dishes(category):
64
  html_content += "</div>"
65
  return html_content
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  # Main Gradio App
68
  with gr.Blocks() as demo:
69
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
70
 
71
- # CSS for small buttons
72
- gr.HTML("""
73
- <style>
74
- #small-btn {
75
- padding: 5px 10px;
76
- font-size: 14px;
77
- border-radius: 5px;
78
- margin: 5px;
79
- }
80
- </style>
81
- """)
82
-
83
- # Buttons for category selection
84
  with gr.Row():
85
- btn_all = gr.Button("ALL", elem_id="small-btn")
86
- btn_vegan = gr.Button("VEGAN", elem_id="small-btn")
87
- btn_halal = gr.Button("HALAL", elem_id="small-btn")
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  # Dish display
90
  dish_display = gr.HTML(value=display_dishes("ALL"))
91
 
92
- # JavaScript for managing the pop-up
93
- gr.HTML(f"""
94
- <div id="popup" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
95
- background-color: white; padding: 20px; border-radius: 10px;
96
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 500px;">
97
- <span onclick="closePopup()" style="position: absolute; top: 10px; right: 10px; cursor: pointer; font-size: 20px;">&times;</span>
98
-
99
- <img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
100
- <h2 id="popup-title" style="margin-top: 20px; color: #444;"></h2>
101
- <p id="popup-description" style="margin-top: 10px; font-size: 16px; color: #666;"></p>
102
- <p id="popup-price" style="margin-top: 10px; font-size: 16px; color: #444;"></p>
103
-
104
- <h4 style="text-align: left; margin-top: 20px;">Choose Extras</h4>
105
- <div style="display: flex; flex-wrap: wrap; justify-content: space-between; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
106
- <label style="margin-right: 10px;"><input type="checkbox" name="extras" value="Extra Raitha"> Extra Raitha</label>
107
- <label style="margin-right: 10px;"><input type="checkbox" name="extras" value="Extra Salan"> Extra Salan</label>
108
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- <button onclick="addToCart()"
111
- style="margin-top: 20px; padding: 10px 20px; background-color: #007bff; color: white; border: none;
112
- border-radius: 5px; cursor: pointer;">Add to Cart</button>
113
- </div>
114
- <script>
115
- function showPopup(image, title, description, price) {{
116
- document.getElementById('popup-image').src = image;
117
- document.getElementById('popup-title').textContent = title;
118
- document.getElementById('popup-description').textContent = description;
119
- document.getElementById('popup-price').textContent = "Price: " + price;
120
-
121
- // Display the popup
122
- document.getElementById('popup').style.display = 'block';
123
- }}
124
- function closePopup() {{
125
- document.getElementById('popup').style.display = 'none';
126
- }}
127
- function addToCart() {{
128
- const extras = Array.from(document.querySelectorAll('input[name=extras]:checked'))
129
- .map(extra => extra.value)
130
- .join(", ");
131
- alert("Item added to cart with extras: " + extras);
132
- closePopup();
133
- }}
134
- </script>
135
- """)
136
-
137
-
138
- # Button click events
139
- btn_all.click(
140
- lambda: gr.update(value=display_dishes("ALL")),
141
- outputs=dish_display
142
- )
143
- btn_vegan.click(
144
- lambda: gr.update(value=display_dishes("VEGAN")),
145
- outputs=dish_display
146
- )
147
- btn_halal.click(
148
- lambda: gr.update(value=display_dishes("HALAL")),
149
- outputs=dish_display
150
- )
151
-
152
- demo.launch()
 
64
  html_content += "</div>"
65
  return html_content
66
 
67
+ def add_to_cart(item_name, item_price):
68
+ cart_items.append({"name": item_name, "price": item_price})
69
+ return f"{item_name} added to cart!"
70
+
71
+ # Display cart items
72
+ def display_cart():
73
+ if not cart_items:
74
+ return "<p>Your cart is empty.</p>"
75
+ html_content = "<ul>"
76
+ for item in cart_items:
77
+ html_content += f"<li>{item['name']} - ${item['price']}</li>"
78
+ html_content += "</ul>"
79
+ return html_content
80
+
81
  # Main Gradio App
82
  with gr.Blocks() as demo:
83
  gr.HTML("<h1 style='text-align: center; color: #333;'>πŸ› Biryani Hub Menu πŸ›</h1>")
84
 
85
+ # Header with category buttons and cart icon
 
 
 
 
 
 
 
 
 
 
 
 
86
  with gr.Row():
87
+ with gr.Column(scale=6, min_width=300):
88
+ gr.HTML("""
89
+ <div style="text-align: left;">
90
+ <button id="btn-all" onclick="filterDishes('ALL')" style="padding: 5px 10px; margin: 5px;">ALL</button>
91
+ <button id="btn-vegan" onclick="filterDishes('VEGAN')" style="padding: 5px 10px; margin: 5px;">VEGAN</button>
92
+ <button id="btn-halal" onclick="filterDishes('HALAL')" style="padding: 5px 10px; margin: 5px;">HALAL</button>
93
+ </div>
94
+ """)
95
+ with gr.Column(scale=1, min_width=50):
96
+ gr.HTML("""
97
+ <div style="text-align: right;">
98
+ <button onclick="showCart()" style="background: none; border: none; cursor: pointer;">
99
+ πŸ›’ Cart
100
+ </button>
101
+ </div>
102
+ """)
103
 
104
  # Dish display
105
  dish_display = gr.HTML(value=display_dishes("ALL"))
106
 
107
+ # Cart display
108
+ cart_display = gr.HTML(value="<p>Your cart is empty.</p>")
109
+
110
+ # JavaScript functions
111
+ gr.HTML("""
112
+ <script>
113
+ function filterDishes(category) {
114
+ fetch(`/filter_dishes?category=${category}`)
115
+ .then(response => response.json())
116
+ .then(data => {
117
+ document.querySelector('#dish-display').innerHTML = data.html;
118
+ });
119
+ }
120
+
121
+ function addToCart(name, price) {
122
+ fetch(`/add_to_cart?item_name=${name}&item_price=${price}`)
123
+ .then(response => response.text())
124
+ .then(alert);
125
+ }
126
+
127
+ function showCart() {
128
+ fetch(`/display_cart`)
129
+ .then(response => response.text())
130
+ .then(data => {
131
+ document.querySelector('#cart-display').innerHTML = data;
132
+ });
133
+ }
134
+ </script>
135
+ """)
136
 
137
+ demo.launch()