Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,115 +1,119 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
# Data
|
| 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 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
return
|
| 53 |
-
|
| 54 |
-
#
|
| 55 |
-
def
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
""
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
with gr.Row():
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
app = create_app()
|
| 115 |
-
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import qrcode
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
+
# Data storage (for prototyping; switch to Salesforce or database for production)
|
| 7 |
+
customer_data_path = "customer_data.xlsx"
|
| 8 |
+
order_data_path = "order_data.xlsx"
|
| 9 |
+
|
| 10 |
+
# Ensure data files exist
|
| 11 |
+
if not os.path.exists(customer_data_path):
|
| 12 |
+
pd.DataFrame(columns=["Name", "Email", "Phone", "Preferences", "Allergies"]).to_excel(customer_data_path, index=False)
|
| 13 |
+
|
| 14 |
+
if not os.path.exists(order_data_path):
|
| 15 |
+
pd.DataFrame(columns=["Table", "Customer", "Order", "Status"]).to_excel(order_data_path, index=False)
|
| 16 |
+
|
| 17 |
+
# Sample menu (can be dynamically loaded from an external file)
|
| 18 |
+
menu = {
|
| 19 |
+
"Bread": ["Roti", "Naan", "Paratha"],
|
| 20 |
+
"Veg Curries": ["Paneer Butter Masala", "Mix Veg", "Dal Tadka"],
|
| 21 |
+
"Non-Veg Curries": ["Chicken Curry", "Mutton Korma", "Fish Curry"],
|
| 22 |
+
"Biryanis": ["Veg Biryani", "Chicken Biryani", "Mutton Biryani"]
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Generate QR Code for each table
|
| 26 |
+
def generate_qr(table_number):
|
| 27 |
+
qr = qrcode.make(f"https://your-huggingface-space/{table_number}")
|
| 28 |
+
qr_path = f"table_{table_number}_qr.png"
|
| 29 |
+
qr.save(qr_path)
|
| 30 |
+
return qr_path
|
| 31 |
+
|
| 32 |
+
# Sign-Up functionality
|
| 33 |
+
def sign_up(name, email, phone, preferences, allergies):
|
| 34 |
+
customer_data = pd.read_excel(customer_data_path)
|
| 35 |
+
if email in customer_data["Email"].values:
|
| 36 |
+
return "Email already exists! Please log in."
|
| 37 |
+
new_entry = {"Name": name, "Email": email, "Phone": phone, "Preferences": preferences, "Allergies": allergies}
|
| 38 |
+
customer_data = customer_data.append(new_entry, ignore_index=True)
|
| 39 |
+
customer_data.to_excel(customer_data_path, index=False)
|
| 40 |
+
return "Sign-Up successful! Please log in."
|
| 41 |
+
|
| 42 |
+
# Login functionality
|
| 43 |
+
def login(email):
|
| 44 |
+
customer_data = pd.read_excel(customer_data_path)
|
| 45 |
+
if email in customer_data["Email"].values:
|
| 46 |
+
customer = customer_data[customer_data["Email"] == email].iloc[0]
|
| 47 |
+
return f"Welcome back, {customer['Name']}!", customer.to_dict()
|
| 48 |
+
return "Email not found! Please sign up.", None
|
| 49 |
+
|
| 50 |
+
# Display menu based on preferences
|
| 51 |
+
def display_menu(preferences, allergies):
|
| 52 |
+
filtered_menu = {}
|
| 53 |
+
for category, items in menu.items():
|
| 54 |
+
filtered_menu[category] = [item for item in items if item not in allergies]
|
| 55 |
+
return filtered_menu
|
| 56 |
+
|
| 57 |
+
# Add item to order
|
| 58 |
+
def add_to_order(table, customer, item):
|
| 59 |
+
order_data = pd.read_excel(order_data_path)
|
| 60 |
+
new_order = {"Table": table, "Customer": customer, "Order": item, "Status": "Pending"}
|
| 61 |
+
order_data = order_data.append(new_order, ignore_index=True)
|
| 62 |
+
order_data.to_excel(order_data_path, index=False)
|
| 63 |
+
return "Item added to order."
|
| 64 |
+
|
| 65 |
+
# Gradio Interface
|
| 66 |
+
with gr.Blocks() as app:
|
| 67 |
+
gr.Markdown("# QR-Based Restaurant Ordering System")
|
| 68 |
+
|
| 69 |
+
# QR Code Section
|
| 70 |
+
with gr.Tab("Generate QR Code"):
|
| 71 |
+
table_input = gr.Number(label="Table Number", value=1)
|
| 72 |
+
qr_output = gr.Image(label="QR Code")
|
| 73 |
+
generate_button = gr.Button("Generate QR Code")
|
| 74 |
+
|
| 75 |
+
generate_button.click(generate_qr, inputs=table_input, outputs=qr_output)
|
| 76 |
+
|
| 77 |
+
# Sign-Up and Login Section
|
| 78 |
+
with gr.Tab("Sign Up / Login"):
|
| 79 |
with gr.Row():
|
| 80 |
+
with gr.Column():
|
| 81 |
+
gr.Markdown("### Sign Up")
|
| 82 |
+
name_input = gr.Textbox(label="Name")
|
| 83 |
+
email_input = gr.Textbox(label="Email")
|
| 84 |
+
phone_input = gr.Textbox(label="Phone")
|
| 85 |
+
preferences_input = gr.Textbox(label="Preferences (e.g., Vegetarian)")
|
| 86 |
+
allergies_input = gr.Textbox(label="Allergies (e.g., Peanuts)")
|
| 87 |
+
sign_up_button = gr.Button("Sign Up")
|
| 88 |
+
sign_up_output = gr.Textbox(label="Sign-Up Status")
|
| 89 |
+
|
| 90 |
+
sign_up_button.click(sign_up,
|
| 91 |
+
inputs=[name_input, email_input, phone_input, preferences_input, allergies_input],
|
| 92 |
+
outputs=sign_up_output)
|
| 93 |
+
|
| 94 |
+
with gr.Column():
|
| 95 |
+
gr.Markdown("### Login")
|
| 96 |
+
login_email_input = gr.Textbox(label="Email")
|
| 97 |
+
login_button = gr.Button("Login")
|
| 98 |
+
login_output = gr.Textbox(label="Login Status")
|
| 99 |
+
|
| 100 |
+
login_button.click(login, inputs=login_email_input, outputs=login_output)
|
| 101 |
+
|
| 102 |
+
# Menu and Ordering Section
|
| 103 |
+
with gr.Tab("Menu & Order"):
|
| 104 |
+
preferences_input = gr.Textbox(label="Preferences (from Login)", interactive=False)
|
| 105 |
+
allergies_input = gr.Textbox(label="Allergies (from Login)", interactive=False)
|
| 106 |
+
menu_display = gr.JSON(label="Filtered Menu")
|
| 107 |
+
display_menu_button = gr.Button("Show Menu")
|
| 108 |
+
|
| 109 |
+
display_menu_button.click(display_menu, inputs=[preferences_input, allergies_input], outputs=menu_display)
|
| 110 |
+
|
| 111 |
+
item_input = gr.Textbox(label="Item to Add")
|
| 112 |
+
table_input = gr.Number(label="Table Number", value=1)
|
| 113 |
+
customer_input = gr.Textbox(label="Customer Name")
|
| 114 |
+
add_order_button = gr.Button("Add to Order")
|
| 115 |
+
add_order_output = gr.Textbox(label="Order Status")
|
| 116 |
+
|
| 117 |
+
add_order_button.click(add_to_order, inputs=[table_input, customer_input, item_input], outputs=add_order_output)
|
| 118 |
+
|
| 119 |
+
app.launch()
|
|
|
|
|
|