Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -257,7 +257,6 @@ modal_and_cart_js = """
|
|
257 |
"""
|
258 |
|
259 |
|
260 |
-
# Gradio app
|
261 |
# Gradio app
|
262 |
def app():
|
263 |
with gr.Blocks() as demo:
|
@@ -268,7 +267,7 @@ def app():
|
|
268 |
active_user = gr.State(None) # No user is active initially
|
269 |
|
270 |
# Signup Page
|
271 |
-
with gr.Row(visible=
|
272 |
gr.Markdown("### Signup Page")
|
273 |
name = gr.Textbox(label="Name")
|
274 |
phone = gr.Textbox(label="Phone Number")
|
@@ -277,62 +276,27 @@ def app():
|
|
277 |
signup_btn = gr.Button("Signup")
|
278 |
signup_message = gr.Label()
|
279 |
|
280 |
-
# Signup callback
|
281 |
-
def handle_signup(name, phone, email, password):
|
282 |
-
message, next_page = signup_user(name, phone, email, password)
|
283 |
-
if next_page == "login":
|
284 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), message
|
285 |
-
return gr.update(), gr.update(), gr.update(), message
|
286 |
-
|
287 |
-
signup_btn.click(
|
288 |
-
handle_signup,
|
289 |
-
inputs=[name, phone, email, password],
|
290 |
-
outputs=[signup_page, login_page, menu_page, signup_message],
|
291 |
-
)
|
292 |
-
|
293 |
# Login Page
|
294 |
-
with gr.Row(visible=
|
295 |
gr.Markdown("### Login Page")
|
296 |
login_email = gr.Textbox(label="Email")
|
297 |
login_password = gr.Textbox(label="Password", type="password")
|
298 |
login_btn = gr.Button("Login")
|
299 |
login_message = gr.Label()
|
300 |
|
301 |
-
# Login callback
|
302 |
-
def handle_login(email, password):
|
303 |
-
message, next_page = validate_login(email, password)
|
304 |
-
if next_page == "menu":
|
305 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), email, message
|
306 |
-
return gr.update(), gr.update(), gr.update(), None, message
|
307 |
-
|
308 |
-
login_btn.click(
|
309 |
-
handle_login,
|
310 |
-
inputs=[login_email, login_password],
|
311 |
-
outputs=[signup_page, login_page, menu_page, active_user, login_message],
|
312 |
-
)
|
313 |
-
|
314 |
# Menu Page
|
315 |
-
with gr.Row(visible=
|
316 |
-
# Adding your original code here without any changes
|
317 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
318 |
|
319 |
-
#
|
320 |
selected_preference = gr.Radio(
|
321 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
322 |
value="All",
|
323 |
label="Choose a Preference",
|
324 |
)
|
325 |
-
|
326 |
-
# Output area for menu items
|
327 |
menu_output = gr.HTML(value=filter_menu("All"))
|
328 |
-
|
329 |
-
# Floating cart display
|
330 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
331 |
-
|
332 |
-
# Final order display
|
333 |
final_order_output = gr.HTML(value="", elem_id="final-order")
|
334 |
-
|
335 |
-
# Modal window
|
336 |
modal_window = gr.HTML("""
|
337 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
338 |
<div style="text-align: right;">
|
@@ -342,7 +306,6 @@ def app():
|
|
342 |
<h2 id="modal-name"></h2>
|
343 |
<p id="modal-description"></p>
|
344 |
<p id="modal-price"></p>
|
345 |
-
<!-- Biryani Extras -->
|
346 |
<label for="biryani-extras">Biryani Extras :</label>
|
347 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
348 |
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
@@ -353,54 +316,38 @@ def app():
|
|
353 |
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
354 |
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
355 |
</div>
|
356 |
-
<!-- Quantity and Special Instructions -->
|
357 |
<label for="quantity">Quantity:</label>
|
358 |
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
359 |
<br><br>
|
360 |
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
361 |
<br><br>
|
362 |
-
<!-- Add to Cart Button -->
|
363 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
364 |
</div>
|
365 |
""")
|
366 |
-
|
367 |
-
# Update menu dynamically based on preference
|
368 |
-
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
369 |
-
|
370 |
-
# Layout
|
371 |
gr.Row([selected_preference])
|
372 |
gr.Row(menu_output)
|
373 |
gr.Row(cart_output)
|
374 |
gr.Row(modal_window)
|
375 |
gr.Row(final_order_output)
|
376 |
gr.HTML(modal_and_cart_js)
|
377 |
-
|
378 |
logout_btn = gr.Button("Logout")
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
|
|
383 |
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
)
|
388 |
|
389 |
-
|
390 |
-
|
391 |
-
if page == "signup":
|
392 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
393 |
-
elif page == "login":
|
394 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
395 |
-
elif page == "menu":
|
396 |
-
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
397 |
|
398 |
-
#
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
outputs=[signup_page, login_page, menu_page],
|
403 |
-
)
|
404 |
|
405 |
return demo
|
406 |
|
|
|
257 |
"""
|
258 |
|
259 |
|
|
|
260 |
# Gradio app
|
261 |
def app():
|
262 |
with gr.Blocks() as demo:
|
|
|
267 |
active_user = gr.State(None) # No user is active initially
|
268 |
|
269 |
# Signup Page
|
270 |
+
with gr.Row(visible=lambda current_page: current_page == "signup") as signup_page:
|
271 |
gr.Markdown("### Signup Page")
|
272 |
name = gr.Textbox(label="Name")
|
273 |
phone = gr.Textbox(label="Phone Number")
|
|
|
276 |
signup_btn = gr.Button("Signup")
|
277 |
signup_message = gr.Label()
|
278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
# Login Page
|
280 |
+
with gr.Row(visible=lambda current_page: current_page == "login") as login_page:
|
281 |
gr.Markdown("### Login Page")
|
282 |
login_email = gr.Textbox(label="Email")
|
283 |
login_password = gr.Textbox(label="Password", type="password")
|
284 |
login_btn = gr.Button("Login")
|
285 |
login_message = gr.Label()
|
286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
# Menu Page
|
288 |
+
with gr.Row(visible=lambda current_page: current_page == "menu") as menu_page:
|
|
|
289 |
gr.Markdown("### Menu Page (Accessible Only After Login)")
|
290 |
|
291 |
+
# Adding your original code here without any changes
|
292 |
selected_preference = gr.Radio(
|
293 |
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
294 |
value="All",
|
295 |
label="Choose a Preference",
|
296 |
)
|
|
|
|
|
297 |
menu_output = gr.HTML(value=filter_menu("All"))
|
|
|
|
|
298 |
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
|
|
|
|
299 |
final_order_output = gr.HTML(value="", elem_id="final-order")
|
|
|
|
|
300 |
modal_window = gr.HTML("""
|
301 |
<div id="modal" style="display: none; position: fixed; background: white; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); padding: 20px; z-index: 1000;">
|
302 |
<div style="text-align: right;">
|
|
|
306 |
<h2 id="modal-name"></h2>
|
307 |
<p id="modal-description"></p>
|
308 |
<p id="modal-price"></p>
|
|
|
309 |
<label for="biryani-extras">Biryani Extras :</label>
|
310 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
311 |
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
|
|
316 |
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
317 |
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
318 |
</div>
|
|
|
319 |
<label for="quantity">Quantity:</label>
|
320 |
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
321 |
<br><br>
|
322 |
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
323 |
<br><br>
|
|
|
324 |
<button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="addToCart()">Add to Cart</button>
|
325 |
</div>
|
326 |
""")
|
|
|
|
|
|
|
|
|
|
|
327 |
gr.Row([selected_preference])
|
328 |
gr.Row(menu_output)
|
329 |
gr.Row(cart_output)
|
330 |
gr.Row(modal_window)
|
331 |
gr.Row(final_order_output)
|
332 |
gr.HTML(modal_and_cart_js)
|
|
|
333 |
logout_btn = gr.Button("Logout")
|
334 |
|
335 |
+
# Callback functions for page navigation
|
336 |
+
def handle_signup(name, phone, email, password):
|
337 |
+
message, next_page = signup_user(name, phone, email, password)
|
338 |
+
return message, next_page
|
339 |
|
340 |
+
def handle_login(email, password):
|
341 |
+
message, next_page = validate_login(email, password)
|
342 |
+
return message, next_page
|
|
|
343 |
|
344 |
+
def handle_logout():
|
345 |
+
return "Logged out!", "signup"
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
|
347 |
+
# Button Click Callbacks
|
348 |
+
signup_btn.click(handle_signup, [name, phone, email, password], [signup_message, current_page])
|
349 |
+
login_btn.click(handle_login, [login_email, login_password], [login_message, current_page])
|
350 |
+
logout_btn.click(handle_logout, outputs=[menu_output, current_page])
|
|
|
|
|
351 |
|
352 |
return demo
|
353 |
|