Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from utils.database_handler import check_credentials, save_user
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def load_menu():
|
| 7 |
-
menu_file = "menu.xlsx" # Ensure this file exists
|
| 8 |
try:
|
| 9 |
return pd.read_excel(menu_file)
|
| 10 |
except Exception as e:
|
|
@@ -25,21 +40,21 @@ def filter_menu(preference):
|
|
| 25 |
html_content = ""
|
| 26 |
for _, item in filtered_data.iterrows():
|
| 27 |
html_content += f"""
|
| 28 |
-
<div style
|
| 29 |
-
<div style
|
| 30 |
-
<h3 style
|
| 31 |
-
<p style
|
| 32 |
-
<p style
|
| 33 |
</div>
|
| 34 |
-
<div style
|
| 35 |
-
<img src
|
| 36 |
-
<button style
|
| 37 |
</div>
|
| 38 |
</div>
|
| 39 |
"""
|
| 40 |
return html_content
|
| 41 |
|
| 42 |
-
# JavaScript for modal and cart behavior
|
| 43 |
modal_and_cart_js = """
|
| 44 |
<style>
|
| 45 |
.cart-container {
|
|
@@ -220,166 +235,98 @@ modal_and_cart_js = """
|
|
| 220 |
</script>
|
| 221 |
"""
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
return (
|
| 228 |
-
gr.update(visible=False), # Hide login page
|
| 229 |
-
gr.update(visible=True), # Show preferences page
|
| 230 |
-
gr.update(visible=True), # Show menu page
|
| 231 |
-
"", # Clear any error message
|
| 232 |
-
)
|
| 233 |
-
else:
|
| 234 |
-
return (
|
| 235 |
-
gr.update(visible=True), # Show error box
|
| 236 |
-
gr.update(visible=False), # Keep preferences page hidden
|
| 237 |
-
gr.update(visible=False), # Keep menu page hidden
|
| 238 |
-
"Invalid email or password. Try again.", # Error message
|
| 239 |
-
)
|
| 240 |
-
|
| 241 |
-
def navigate_to_signup():
|
| 242 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 243 |
-
|
| 244 |
-
def create_account(name, phone, email, password):
|
| 245 |
-
if save_user(name, phone, email, password):
|
| 246 |
-
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 247 |
-
else:
|
| 248 |
-
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
| 249 |
-
|
| 250 |
-
def navigate_to_login():
|
| 251 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 252 |
-
|
| 253 |
-
with gr.Blocks() as app:
|
| 254 |
-
# Login Page
|
| 255 |
-
with gr.Column(visible=True) as login_section:
|
| 256 |
-
gr.Markdown("# Login Page")
|
| 257 |
-
email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 258 |
-
password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
| 259 |
-
error_box = gr.Markdown("", visible=False)
|
| 260 |
-
login_btn = gr.Button("Login")
|
| 261 |
-
create_account_btn = gr.Button("Create an Account")
|
| 262 |
-
|
| 263 |
-
# Sign-Up Page
|
| 264 |
-
with gr.Column(visible=False) as signup_section:
|
| 265 |
-
gr.Markdown("# Sign Up Page")
|
| 266 |
-
name = gr.Textbox(label="Name", placeholder="Enter your full name")
|
| 267 |
-
phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
|
| 268 |
-
signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 269 |
-
signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
|
| 270 |
-
success_message = gr.Markdown("", visible=False)
|
| 271 |
-
error_message = gr.Markdown("", visible=False)
|
| 272 |
-
submit_btn = gr.Button("Sign Up")
|
| 273 |
-
back_to_login_btn = gr.Button("Back to Login")
|
| 274 |
-
|
| 275 |
-
# Preferences Page
|
| 276 |
-
with gr.Column(visible=False) as preference_section:
|
| 277 |
-
gr.Markdown("# Preferences Page")
|
| 278 |
-
|
| 279 |
-
# Menu Page
|
| 280 |
-
with gr.Column(visible=False) as menu_section:
|
| 281 |
-
gr.Markdown("## Dynamic Menu with Preferences")
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
)
|
| 300 |
-
create_account_btn.click(
|
| 301 |
-
navigate_to_signup,
|
| 302 |
-
inputs=[],
|
| 303 |
-
outputs=[login_section, signup_section],
|
| 304 |
-
)
|
| 305 |
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
navigate_to_login,
|
| 314 |
-
inputs=[],
|
| 315 |
-
outputs=[login_section, signup_section],
|
| 316 |
-
)
|
| 317 |
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
with gr.Blocks() as demo:
|
| 321 |
-
gr.Markdown("## Dynamic Menu with Preferences")
|
| 322 |
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 326 |
-
value="All",
|
| 327 |
-
label="Choose a Preference",
|
| 328 |
-
)
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
# Modal window
|
| 340 |
-
modal_window = gr.HTML("""
|
| 341 |
-
<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;">
|
| 342 |
-
<div style="text-align: right;">
|
| 343 |
-
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
| 344 |
-
</div>
|
| 345 |
-
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
| 346 |
-
<h2 id="modal-name"></h2>
|
| 347 |
-
<p id="modal-description"></p>
|
| 348 |
-
<p id="modal-price"></p>
|
| 349 |
-
<!-- Biryani Extras -->
|
| 350 |
-
<label for="biryani-extras">Biryani Extras :</label>
|
| 351 |
-
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 352 |
-
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
| 353 |
-
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
| 354 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
| 355 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
| 356 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
| 357 |
-
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
| 358 |
-
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
| 359 |
-
</div>
|
| 360 |
-
<!-- Quantity and Special Instructions -->
|
| 361 |
-
<label for="quantity">Quantity:</label>
|
| 362 |
-
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
| 363 |
-
<br><br>
|
| 364 |
-
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
| 365 |
-
<br><br>
|
| 366 |
-
<!-- Add to Cart Button -->
|
| 367 |
-
<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>
|
| 368 |
-
</div>
|
| 369 |
-
""")
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
-
# Layout
|
| 375 |
-
gr.Row([selected_preference])
|
| 376 |
-
gr.Row(menu_output)
|
| 377 |
-
gr.Row(cart_output)
|
| 378 |
-
gr.Row(modal_window)
|
| 379 |
-
gr.Row(final_order_output)
|
| 380 |
-
gr.HTML(modal_and_cart_js)
|
| 381 |
return demo
|
| 382 |
|
| 383 |
if __name__ == "__main__":
|
| 384 |
-
|
| 385 |
-
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
# In-memory storage for user credentials
|
| 5 |
+
users = {"admin": "password"} # Example credentials (username: password)
|
| 6 |
+
|
| 7 |
+
# Function to validate login
|
| 8 |
+
def validate_login(username, password):
|
| 9 |
+
if username in users and users[username] == password:
|
| 10 |
+
return True, "Login successful! Redirecting to the menu page..."
|
| 11 |
+
return False, "Invalid username or password. Please try again."
|
| 12 |
+
|
| 13 |
+
# Function to register a new user
|
| 14 |
+
def signup_user(username, password):
|
| 15 |
+
if username in users:
|
| 16 |
+
return "Username already exists. Please choose a different username."
|
| 17 |
+
users[username] = password
|
| 18 |
+
return "Signup successful! Please log in."
|
| 19 |
+
|
| 20 |
+
# Function to load menu data
|
| 21 |
def load_menu():
|
| 22 |
+
menu_file = "menu.xlsx" # Ensure this file exists
|
| 23 |
try:
|
| 24 |
return pd.read_excel(menu_file)
|
| 25 |
except Exception as e:
|
|
|
|
| 40 |
html_content = ""
|
| 41 |
for _, item in filtered_data.iterrows():
|
| 42 |
html_content += f"""
|
| 43 |
+
<div style="display: flex; align-items: center; border: 1px solid #ddd; border-radius: 8px; padding: 15px; margin-bottom: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);">
|
| 44 |
+
<div style="flex: 1; margin-right: 15px;">
|
| 45 |
+
<h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
|
| 46 |
+
<p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
|
| 47 |
+
<p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
|
| 48 |
</div>
|
| 49 |
+
<div style="flex-shrink: 0; text-align: center;">
|
| 50 |
+
<img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
|
| 51 |
+
<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 ($)']}')">Add</button>
|
| 52 |
</div>
|
| 53 |
</div>
|
| 54 |
"""
|
| 55 |
return html_content
|
| 56 |
|
| 57 |
+
# JavaScript for modal and cart behavior (unchanged)
|
| 58 |
modal_and_cart_js = """
|
| 59 |
<style>
|
| 60 |
.cart-container {
|
|
|
|
| 235 |
</script>
|
| 236 |
"""
|
| 237 |
|
| 238 |
+
# Gradio app definition
|
| 239 |
+
def app():
|
| 240 |
+
with gr.Blocks() as demo:
|
| 241 |
+
gr.Markdown("## Dynamic Menu with Preferences")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
# Login and Signup Tabs
|
| 244 |
+
with gr.Tabs():
|
| 245 |
+
with gr.Tab("Login"):
|
| 246 |
+
gr.Markdown("### Login Page")
|
| 247 |
+
username = gr.Textbox(label="Username")
|
| 248 |
+
password = gr.Textbox(label="Password", type="password")
|
| 249 |
+
login_btn = gr.Button("Login")
|
| 250 |
+
login_message = gr.Label()
|
| 251 |
|
| 252 |
+
login_btn.click(
|
| 253 |
+
validate_login,
|
| 254 |
+
inputs=[username, password],
|
| 255 |
+
outputs=[login_message],
|
| 256 |
+
)
|
| 257 |
|
| 258 |
+
with gr.Tab("Signup"):
|
| 259 |
+
gr.Markdown("### Signup Page")
|
| 260 |
+
signup_username = gr.Textbox(label="Username")
|
| 261 |
+
signup_password = gr.Textbox(label="Password", type="password")
|
| 262 |
+
signup_btn = gr.Button("Signup")
|
| 263 |
+
signup_message = gr.Label()
|
| 264 |
|
| 265 |
+
signup_btn.click(
|
| 266 |
+
signup_user,
|
| 267 |
+
inputs=[signup_username, signup_password],
|
| 268 |
+
outputs=[signup_message],
|
| 269 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
+
with gr.Tab("Menu Page"):
|
| 272 |
+
gr.Markdown("### Menu Page")
|
| 273 |
+
selected_preference = gr.Radio(
|
| 274 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 275 |
+
value="All",
|
| 276 |
+
label="Choose a Preference",
|
| 277 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
+
# Output area for menu items
|
| 280 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
|
|
|
|
|
|
| 281 |
|
| 282 |
+
# Floating cart display
|
| 283 |
+
cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
+
# Final order display
|
| 286 |
+
final_order_output = gr.HTML(value="", elem_id="final-order")
|
| 287 |
|
| 288 |
+
# Modal window
|
| 289 |
+
modal_window = gr.HTML("""
|
| 290 |
+
<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;">
|
| 291 |
+
<div style="text-align: right;">
|
| 292 |
+
<button onclick="closeModal()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
|
| 293 |
+
</div>
|
| 294 |
+
<img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 20px;" />
|
| 295 |
+
<h2 id="modal-name"></h2>
|
| 296 |
+
<p id="modal-description"></p>
|
| 297 |
+
<p id="modal-price"></p>
|
| 298 |
+
<label for="biryani-extras">Biryani Extras:</label>
|
| 299 |
+
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 300 |
+
<label><input type="checkbox" name="biryani-extra" value="Thums up" /> Thums up + $2.00</label>
|
| 301 |
+
<label><input type="checkbox" name="biryani-extra" value="Sprite" /> Sprite + $2.00</label>
|
| 302 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha" /> Extra Raitha + $1.00</label>
|
| 303 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan" /> Extra Salan + $2.00</label>
|
| 304 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
| 305 |
+
<label><input type="checkbox" name="biryani-extra" value="Chilli Chicken" /> Chilli Chicken + $14.00</label>
|
| 306 |
+
<label><input type="checkbox" name="biryani-extra" value="Veg Manchurian" /> Veg Manchurian + $12.00</label>
|
| 307 |
+
</div>
|
| 308 |
+
<label for="quantity">Quantity:</label>
|
| 309 |
+
<input type="number" id="quantity" value="1" min="1" style="width: 50px;" />
|
| 310 |
+
<br><br>
|
| 311 |
+
<textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 60px;"></textarea>
|
| 312 |
+
<br><br>
|
| 313 |
+
<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>
|
| 314 |
+
</div>
|
| 315 |
+
""")
|
| 316 |
|
| 317 |
+
# Update menu dynamically based on preference
|
| 318 |
+
selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
|
| 320 |
+
# Layout
|
| 321 |
+
gr.Row([selected_preference])
|
| 322 |
+
gr.Row(menu_output)
|
| 323 |
+
gr.Row(cart_output)
|
| 324 |
+
gr.Row(modal_window)
|
| 325 |
+
gr.Row(final_order_output)
|
| 326 |
+
gr.HTML(modal_and_cart_js)
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
return demo
|
| 329 |
|
| 330 |
if __name__ == "__main__":
|
| 331 |
+
demo = app()
|
| 332 |
+
demo.launch()
|