nagasurendra commited on
Commit
6ff2f86
·
verified ·
1 Parent(s): 0c44a73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -39
app.py CHANGED
@@ -301,41 +301,38 @@ def create_account(name, phone, email, password):
301
 
302
  def navigate_to_login():
303
  return gr.update(visible=True), gr.update(visible=False)
304
- # Modal HTML Content
305
- MODAL_HTML = """
306
- <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;">
307
- <div style="text-align: right;">
308
- <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
309
- </div>
310
- <img id="modal-image" style="width: 100%; height: 300px; border-radius: 8px; margin-bottom: 20px;" />
311
- <h2 id="modal-name"></h2>
312
- <p id="modal-description"></p>
313
- <p id="modal-price"></p>
314
- <!-- Biryani Extras -->
315
- <label for="biryani-extras">Extras :</label>
316
- <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
317
- <label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
318
- <label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
319
- <label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
320
- <label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
321
- <label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
322
- <label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
323
- <label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
324
- </div>
325
- <!-- Quantity and Special Instructions -->
326
- <label for="quantity">Quantity:</label>
327
- <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
328
- <br><br>
329
- <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
330
- <br><br>
331
- <!-- Add to Cart Button -->
332
- <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>
333
- </div>
334
  """
335
 
336
  # Gradio App
337
  def app():
338
  with gr.Blocks() as demo:
 
339
  # Login Page
340
  with gr.Column(visible=True) as login_section:
341
  gr.Markdown("# Login Page")
@@ -366,25 +363,56 @@ def app():
366
  value="All",
367
  label="Choose a Preference",
368
  )
369
-
370
- # Add the same view_cart_button in two positions
371
- view_cart_button = gr.Button("View Cart")
372
 
373
  # Output area for menu items
374
  menu_output = gr.HTML(value=filter_menu("All"))
375
 
376
- # Modal window using the pre-defined MODAL_HTML
377
- modal_window = gr.HTML(MODAL_HTML)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
 
379
  # Layout
380
  gr.Row([selected_preference])
381
- gr.Row(view_cart_button) # First position for view_cart_button
382
  gr.Row(menu_output)
383
- gr.Row(view_cart_button) # Second position for view_cart_button
384
  gr.Row(modal_window)
385
  gr.HTML(modal_and_cart_js)
386
 
387
- # Cart & Final Order Page
388
  with gr.Column(visible=False) as cart_section:
389
  gr.Markdown("### Cart & Final Order Page")
390
 
@@ -437,4 +465,4 @@ def app():
437
  return demo
438
 
439
  if __name__ == "__main__":
440
- app().launch()
 
301
 
302
  def navigate_to_login():
303
  return gr.update(visible=True), gr.update(visible=False)
304
+
305
+ """
306
+ # Authentication and Navigation Logic
307
+ def authenticate_user(email, password):
308
+ if check_credentials(email, password):
309
+ return gr.update(visible=False), gr.update(visible=True), ""
310
+ else:
311
+ return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."
312
+
313
+ def navigate_to_signup():
314
+ return gr.update(visible=False), gr.update(visible=True)
315
+
316
+ def create_account(name, phone, email, password):
317
+ if save_user(name, phone, email, password):
318
+ return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
319
+ else:
320
+ return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
321
+
322
+ def navigate_to_login():
323
+ return gr.update(visible=True), gr.update(visible=False)
324
+ SCROLL_TO_TOP_JS = """
325
+ <script>
326
+ function scrollToTop() {
327
+ window.scrollTo({ top: 0, behavior: 'smooth' });
328
+ }
329
+ </script>
 
 
 
 
330
  """
331
 
332
  # Gradio App
333
  def app():
334
  with gr.Blocks() as demo:
335
+ demo.append(gr.HTML(SCROLL_TO_TOP_JS))
336
  # Login Page
337
  with gr.Column(visible=True) as login_section:
338
  gr.Markdown("# Login Page")
 
363
  value="All",
364
  label="Choose a Preference",
365
  )
366
+ empty_div = gr.HTML('<div style="height: 20px;"></div>')
 
 
367
 
368
  # Output area for menu items
369
  menu_output = gr.HTML(value=filter_menu("All"))
370
 
371
+ # Button to navigate to Cart Page
372
+ view_cart_button = gr.Button("View Cart")
373
+ empty_div = gr.HTML('<div style="height: 300px;"></div>')
374
+
375
+ # Modal window
376
+ modal_window = gr.HTML("""
377
+ <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;">
378
+ <div style="text-align: right;">
379
+ <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
380
+ </div>
381
+ <img id="modal-image" style="width: 100%; height: 300px; border-radius: 8px; margin-bottom: 20px;" />
382
+ <h2 id="modal-name"></h2>
383
+ <p id="modal-description"></p>
384
+ <p id="modal-price"></p>
385
+ <!-- Biryani Extras -->
386
+ <label for="biryani-extras">Extras :</label>
387
+ <div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
388
+ <label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
389
+ <label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
390
+ <label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
391
+ <label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
392
+ <label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
393
+ <label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
394
+ <label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
395
+ </div>
396
+ <!-- Quantity and Special Instructions -->
397
+ <label for="quantity">Quantity:</label>
398
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
399
+ <br><br>
400
+ <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
401
+ <br><br>
402
+ <!-- Add to Cart Button -->
403
+ <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>
404
+ </div>
405
+ """)
406
+ # Update menu dynamically based on preference
407
+ selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
408
 
409
  # Layout
410
  gr.Row([selected_preference])
 
411
  gr.Row(menu_output)
 
412
  gr.Row(modal_window)
413
  gr.HTML(modal_and_cart_js)
414
 
415
+ # Cart & Final Order Page
416
  with gr.Column(visible=False) as cart_section:
417
  gr.Markdown("### Cart & Final Order Page")
418
 
 
465
  return demo
466
 
467
  if __name__ == "__main__":
468
+ app().launch()