Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,90 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
|
|
|
|
|
|
| 33 |
with gr.Blocks() as app:
|
| 34 |
# Login Page
|
| 35 |
with gr.Column(visible=True) as login_section:
|
|
@@ -48,41 +103,28 @@ def app_interface():
|
|
| 48 |
signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 49 |
signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
|
| 50 |
success_message = gr.Markdown("", visible=False)
|
| 51 |
-
error_message = gr.Markdown("", visible=False)
|
| 52 |
submit_btn = gr.Button("Sign Up")
|
| 53 |
back_to_login_btn = gr.Button("Back to Login")
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
with gr.Column(visible=False) as
|
| 57 |
-
gr.Markdown("#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
create_account_btn.click(
|
| 66 |
-
navigate_to_signup,
|
| 67 |
-
inputs=[],
|
| 68 |
-
outputs=[login_section, signup_section],
|
| 69 |
-
)
|
| 70 |
|
| 71 |
-
# Button Actions
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
)
|
| 77 |
-
back_to_login_btn.click(
|
| 78 |
-
navigate_to_login,
|
| 79 |
-
inputs=[],
|
| 80 |
-
outputs=[login_section, signup_section],
|
| 81 |
-
)
|
| 82 |
|
| 83 |
return app
|
| 84 |
|
| 85 |
-
|
| 86 |
if __name__ == "__main__":
|
| 87 |
app = app_interface()
|
| 88 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from utils.database_handler import check_credentials, save_user # Ensure you have these utility functions implemented.
|
| 4 |
|
| 5 |
+
# Function to load the menu data
|
| 6 |
+
def load_menu():
|
| 7 |
+
menu_file = "menu.xlsx" # Ensure this file exists in the same directory
|
| 8 |
+
try:
|
| 9 |
+
return pd.read_excel(menu_file)
|
| 10 |
+
except Exception as e:
|
| 11 |
+
raise ValueError(f"Error loading menu file: {e}")
|
| 12 |
|
| 13 |
+
# Initialize cart globally
|
| 14 |
+
cart_items = []
|
| 15 |
+
|
| 16 |
+
# Pricing for extras
|
| 17 |
+
EXTRAS_PRICES = {
|
| 18 |
+
"Extra Raitha 4oz": 1,
|
| 19 |
+
"Extra Raitha 8oz": 2,
|
| 20 |
+
"Extra Salan 4oz": 1,
|
| 21 |
+
"Extra Salan 8oz": 2,
|
| 22 |
+
"Extra Onion": 1,
|
| 23 |
+
"Extra Onion & Lemon": 2,
|
| 24 |
+
"Extra Fried Onion 4oz": 2,
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Function to filter menu items based on preference
|
| 28 |
+
def filter_menu(preference):
|
| 29 |
+
menu_data = load_menu()
|
| 30 |
+
if preference == "Halal/Non-Veg":
|
| 31 |
+
filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
| 32 |
+
elif preference == "Vegetarian":
|
| 33 |
+
filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
|
| 34 |
+
elif preference == "Guilt-Free":
|
| 35 |
+
filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
|
| 36 |
+
else:
|
| 37 |
+
filtered_data = menu_data
|
| 38 |
+
|
| 39 |
+
html_content = ""
|
| 40 |
+
for _, item in filtered_data.iterrows():
|
| 41 |
+
html_content += f"""
|
| 42 |
+
<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);\">
|
| 43 |
+
<div style=\"flex: 1; margin-right: 15px;\">
|
| 44 |
+
<h3 style=\"margin: 0; font-size: 18px;\">{item['Dish Name']}</h3>
|
| 45 |
+
<p style=\"margin: 5px 0; font-size: 16px; color: #888;\">${item['Price ($)']}</p>
|
| 46 |
+
<p style=\"margin: 5px 0; font-size: 14px; color: #555;\">{item['Description']}</p>
|
| 47 |
+
</div>
|
| 48 |
+
<div style=\"flex-shrink: 0; text-align: center;\">
|
| 49 |
+
<img src=\"{item['Image URL']}\" alt=\"{item['Dish Name']}\" style=\"width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;\">
|
| 50 |
+
<button style=\"background-color: #28a745; color: white; border: none; padding: 8px 15px; font-size: 14px; border-radius: 5px; cursor: pointer;\" onclick=\"alert('Added {item['Dish Name']} to cart!')\">Add</button>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
"""
|
| 54 |
+
return html_content
|
| 55 |
+
|
| 56 |
+
# Function to authenticate user
|
| 57 |
+
def authenticate_user(email, password):
|
| 58 |
+
if check_credentials(email, password):
|
| 59 |
+
return (
|
| 60 |
+
gr.update(visible=False), # Hide login page
|
| 61 |
+
gr.update(visible=True), # Show menu page
|
| 62 |
+
"" # Clear any error message
|
| 63 |
+
)
|
| 64 |
+
else:
|
| 65 |
+
return (
|
| 66 |
+
gr.update(visible=True), # Keep login page visible
|
| 67 |
+
gr.update(visible=False), # Keep menu page hidden
|
| 68 |
+
"Invalid email or password. Try again."
|
| 69 |
+
)
|
| 70 |
|
| 71 |
+
# Function to navigate to signup page
|
| 72 |
+
def navigate_to_signup():
|
| 73 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 74 |
|
| 75 |
+
# Function to create account
|
| 76 |
+
def create_account(name, phone, email, password):
|
| 77 |
+
if save_user(name, phone, email, password):
|
| 78 |
+
return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
|
| 79 |
+
else:
|
| 80 |
+
return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)
|
| 81 |
|
| 82 |
+
# Function to navigate back to login page
|
| 83 |
+
def navigate_to_login():
|
| 84 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 85 |
|
| 86 |
+
# Gradio app
|
| 87 |
+
def app_interface():
|
| 88 |
with gr.Blocks() as app:
|
| 89 |
# Login Page
|
| 90 |
with gr.Column(visible=True) as login_section:
|
|
|
|
| 103 |
signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 104 |
signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
|
| 105 |
success_message = gr.Markdown("", visible=False)
|
|
|
|
| 106 |
submit_btn = gr.Button("Sign Up")
|
| 107 |
back_to_login_btn = gr.Button("Back to Login")
|
| 108 |
|
| 109 |
+
# Dynamic Menu Page
|
| 110 |
+
with gr.Column(visible=False) as menu_section:
|
| 111 |
+
gr.Markdown("# Dynamic Menu")
|
| 112 |
+
preference = gr.Radio(
|
| 113 |
+
choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
|
| 114 |
+
value="All",
|
| 115 |
+
label="Choose a Preference"
|
| 116 |
+
)
|
| 117 |
+
menu_output = gr.HTML(value=filter_menu("All"))
|
| 118 |
+
preference.change(filter_menu, inputs=[preference], outputs=[menu_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
# Button Actions
|
| 121 |
+
login_btn.click(authenticate_user, inputs=[email, password], outputs=[login_section, menu_section, error_box])
|
| 122 |
+
create_account_btn.click(navigate_to_signup, inputs=[], outputs=[login_section, signup_section])
|
| 123 |
+
submit_btn.click(create_account, inputs=[name, phone, signup_email, signup_password], outputs=[success_message, signup_section, login_section])
|
| 124 |
+
back_to_login_btn.click(navigate_to_login, inputs=[], outputs=[login_section, signup_section])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
return app
|
| 127 |
|
|
|
|
| 128 |
if __name__ == "__main__":
|
| 129 |
app = app_interface()
|
| 130 |
app.launch()
|