Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from routes.auth import login, sign_up
|
| 3 |
+
|
| 4 |
+
def login_interface():
|
| 5 |
+
def handle_login(email, password):
|
| 6 |
+
success, user_data = login(email, password)
|
| 7 |
+
if success:
|
| 8 |
+
return f"Welcome, {user_data['Name']}! Redirecting to the menu...", gr.update(visible=False), gr.update(visible=True)
|
| 9 |
+
else:
|
| 10 |
+
return "Invalid email or password. Please try again.", gr.update(visible=True), gr.update(visible=False)
|
| 11 |
+
|
| 12 |
+
with gr.Blocks() as login_page:
|
| 13 |
+
gr.Markdown("# Login to BH Restaurant")
|
| 14 |
+
email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 15 |
+
password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
| 16 |
+
error_message = gr.Markdown(visible=False)
|
| 17 |
+
login_button = gr.Button("Login")
|
| 18 |
+
login_button.click(handle_login, inputs=[email, password], outputs=[error_message])
|
| 19 |
+
return login_page
|
| 20 |
+
|
| 21 |
+
def sign_up_interface():
|
| 22 |
+
def handle_sign_up(name, email, password, phone, preferences, allergies):
|
| 23 |
+
success = sign_up(name, email, password, phone, preferences, allergies)
|
| 24 |
+
if success:
|
| 25 |
+
return "Account created successfully! Please log in."
|
| 26 |
+
else:
|
| 27 |
+
return "This email is already registered. Please log in instead."
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as sign_up_page:
|
| 30 |
+
gr.Markdown("# Sign Up for BH Restaurant")
|
| 31 |
+
name = gr.Textbox(label="Name", placeholder="Enter your name")
|
| 32 |
+
email = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 33 |
+
password = gr.Textbox(label="Password", placeholder="Enter a secure password", type="password")
|
| 34 |
+
phone = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
| 35 |
+
preferences = gr.Dropdown(
|
| 36 |
+
label="Food Preferences", choices=["Vegetarian", "Vegan", "Halal", "Complete Menu"]
|
| 37 |
+
)
|
| 38 |
+
allergies = gr.Textbox(label="Allergies", placeholder="List any allergies (comma-separated)")
|
| 39 |
+
sign_up_button = gr.Button("Sign Up")
|
| 40 |
+
output_message = gr.Markdown()
|
| 41 |
+
sign_up_button.click(handle_sign_up, inputs=[name, email, password, phone, preferences, allergies], outputs=[output_message])
|
| 42 |
+
return sign_up_page
|
| 43 |
+
|
| 44 |
+
def main_interface():
|
| 45 |
+
login_page = login_interface()
|
| 46 |
+
sign_up_page = sign_up_interface()
|
| 47 |
+
|
| 48 |
+
with gr.Blocks() as app:
|
| 49 |
+
with gr.Tabs():
|
| 50 |
+
with gr.Tab("Login"):
|
| 51 |
+
login_page.render()
|
| 52 |
+
with gr.Tab("Sign Up"):
|
| 53 |
+
sign_up_page.render()
|
| 54 |
+
return app
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
app = main_interface()
|
| 58 |
+
app.launch()
|