geethareddy commited on
Commit
81b77b9
·
verified ·
1 Parent(s): 6c55065

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -41
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import pandas as pd
3
- from utils.database_handler import check_credentials, save_user # Ensure these functions are implemented
4
 
5
  # Initialize global cart
6
  cart_items = []
@@ -36,7 +35,7 @@ def filter_menu(preference):
36
  </div>
37
  <div style="flex-shrink: 0; text-align: center;">
38
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
39
- <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Price ($)']}')">Add</button>
40
  </div>
41
  </div>
42
  """
@@ -72,58 +71,44 @@ def add_to_cart(name, price, quantity):
72
  # Main Gradio App Interface
73
  def app_interface():
74
  with gr.Blocks() as app:
75
- # Login Section
76
- with gr.Column(visible=True) as login_section:
77
- gr.Markdown("# Login Page")
78
- email = gr.Textbox(label="Email", placeholder="Enter your email")
79
- password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
80
- error_box = gr.Markdown("", visible=False)
81
- login_btn = gr.Button("Login")
82
- create_account_btn = gr.Button("Create an Account")
83
-
84
- # Sign-Up Section
85
- with gr.Column(visible=False) as signup_section:
86
- gr.Markdown("# Sign Up Page")
87
- name = gr.Textbox(label="Name", placeholder="Enter your full name")
88
- phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
89
- signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
90
- signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
91
- signup_btn = gr.Button("Sign Up")
92
- back_to_login_btn = gr.Button("Back to Login")
93
 
94
  # Menu Section
95
- with gr.Column(visible=False) as menu_section:
96
- gr.Markdown("# Dynamic Menu")
97
  preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], label="Filter Menu")
98
- menu_output = gr.HTML()
99
  cart_output = gr.HTML(value="Your cart is empty.")
100
 
101
  # Update menu dynamically based on preference
102
  preference.change(filter_menu, inputs=[preference], outputs=[menu_output])
103
 
104
- # Button Actions for Login
105
- def authenticate_user(email, password):
106
- if check_credentials(email, password):
107
- return gr.update(visible=False), gr.update(visible=True), ""
108
- else:
109
- return gr.update(visible=True), gr.update(visible=False), "Invalid email or password."
110
-
111
- login_btn.click(authenticate_user, inputs=[email, password], outputs=[login_section, menu_section, error_box])
112
-
113
- # Button Actions for Sign-Up
114
- def handle_signup(name, phone, email, password):
115
- if save_user(name, phone, email, password):
116
- return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
117
- else:
118
- return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
119
-
120
- signup_btn.click(handle_signup, inputs=[name, phone, signup_email, signup_password], outputs=[error_box, login_section, signup_section])
121
- back_to_login_btn.click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[login_section, signup_section])
122
 
123
  # Layout for Menu Section
124
  gr.Row([preference])
125
  gr.Row(menu_output)
126
  gr.Row(cart_output)
 
127
 
128
  return app
129
 
 
1
  import gradio as gr
2
  import pandas as pd
 
3
 
4
  # Initialize global cart
5
  cart_items = []
 
35
  </div>
36
  <div style="flex-shrink: 0; text-align: center;">
37
  <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
38
+ <button style="background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;" onclick="openModal('{item['Dish Name']}', '{item['Image URL']}', '{item['Description']}', '{item['Price ($)']}')">View Details</button>
39
  </div>
40
  </div>
41
  """
 
71
  # Main Gradio App Interface
72
  def app_interface():
73
  with gr.Blocks() as app:
74
+ # Header Section
75
+ gr.Markdown("<h1 style='text-align: center; font-size: 36px;'>Dynamic Menu System</h1>")
76
+ gr.Markdown("<p style='text-align: center; font-size: 18px; color: gray;'>Select your preferences and explore the menu</p>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  # Menu Section
79
+ with gr.Column() as menu_section:
80
+ gr.Markdown("# Menu")
81
  preference = gr.Radio(choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"], label="Filter Menu")
82
+ menu_output = gr.HTML(value=filter_menu("All"))
83
  cart_output = gr.HTML(value="Your cart is empty.")
84
 
85
  # Update menu dynamically based on preference
86
  preference.change(filter_menu, inputs=[preference], outputs=[menu_output])
87
 
88
+ # Modal Pop-up Section
89
+ modal_window = gr.HTML("""
90
+ <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; width: 40%; top: 20%; left: 30%; transform: translate(-50%, -50%);">
91
+ <div style="text-align: right;">
92
+ <button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">&times;</button>
93
+ </div>
94
+ <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
95
+ <h2 id="modal-name" style="text-align: center;"></h2>
96
+ <p id="modal-description" style="color: gray; text-align: center;"></p>
97
+ <p id="modal-price" style="font-size: 20px; text-align: center;"></p>
98
+ <label for="quantity">Quantity:</label>
99
+ <input type="number" id="quantity" value="1" min="1" style="width: 50px; margin-bottom: 20px;" />
100
+ <br><br>
101
+ <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px; border-radius: 5px;"></textarea>
102
+ <br><br>
103
+ <button style="background-color: #28a745; color: white; border: none; padding: 10px 20px; font-size: 16px; border-radius: 5px; cursor: pointer; width: 100%;" onclick="addToCart()">Add to Cart</button>
104
+ </div>
105
+ """)
106
 
107
  # Layout for Menu Section
108
  gr.Row([preference])
109
  gr.Row(menu_output)
110
  gr.Row(cart_output)
111
+ gr.Row(modal_window)
112
 
113
  return app
114