File size: 9,234 Bytes
910fa91
06d4dac
d399f77
5032b8c
d399f77
06d4dac
d399f77
 
 
 
 
f00ae41
d399f77
06d4dac
 
d399f77
 
 
 
 
 
 
 
 
06d4dac
d399f77
06d4dac
 
 
 
 
 
 
 
 
cd22a78
06d4dac
 
 
 
566fb77
d399f77
aad651d
d399f77
aad651d
d399f77
 
 
 
 
2f37fba
d399f77
 
 
 
 
cd22a78
d399f77
 
 
dddd65f
aad651d
 
d399f77
 
 
 
 
 
aad651d
d399f77
37ab9ad
d399f77
 
 
 
 
aad651d
d399f77
 
 
 
aad651d
37ab9ad
d399f77
 
 
 
 
 
 
 
aad651d
d399f77
aad651d
dddd65f
d9431d3
dddd65f
d9431d3
dddd65f
 
 
 
 
 
 
d9431d3
aad651d
d399f77
37ab9ad
d399f77
 
 
 
 
f00ae41
d399f77
f00ae41
 
9513916
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f00ae41
 
2f37fba
566fb77
 
2f37fba
f00ae41
1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import gradio as gr
import pandas as pd
from utils.database_handler import check_credentials, save_user

# Function to load the menu data
def load_menu():
    menu_file = "menu.xlsx"  # Ensure this file exists in the same directory
    try:
        return pd.read_excel(menu_file)
    except Exception as e:
        raise ValueError(f"Error loading menu file: {e}")

# Function to filter menu items based on preference
def filter_menu(preference):
    menu_data = load_menu()
    if preference == "Halal/Non-Veg":
        filtered_data = menu_data[menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
    elif preference == "Vegetarian":
        filtered_data = menu_data[~menu_data["Ingredients"].str.contains("Chicken|Mutton|Fish|Prawns|Goat", case=False, na=False)]
    elif preference == "Guilt-Free":
        filtered_data = menu_data[menu_data["Description"].str.contains(r"Fat: ([0-9]|10)g", case=False, na=False)]
    else:
        filtered_data = menu_data

    html_content = ""
    for _, item in filtered_data.iterrows():
        html_content += f"""
        <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);">
            <div style="flex: 1; margin-right: 15px;">
                <h3 style="margin: 0; font-size: 18px;">{item['Dish Name']}</h3>
                <p style="margin: 5px 0; font-size: 16px; color: #888;">${item['Price ($)']}</p>
                <p style="margin: 5px 0; font-size: 14px; color: #555;">{item['Description']}</p>
            </div>
            <div style="flex-shrink: 0; text-align: center;">
                <img src="{item['Image URL']}" alt="{item['Dish Name']}" style="width: 100px; height: 100px; border-radius: 8px; object-fit: cover; margin-bottom: 10px;">
                <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>
            </div>
        </div>
        """
    return html_content

# Login and Signup Functions
def authenticate_user(email, password):
    if check_credentials(email, password):
        return gr.update(visible=False), gr.update(visible=True), ""
    else:
        return gr.update(visible=True), gr.update(visible=False), "Invalid email or password. Try again."

def navigate_to_signup():
    return gr.update(visible=False), gr.update(visible=True)

def create_account(name, phone, email, password):
    if save_user(name, phone, email, password):
        return "Account created successfully! You can now log in.", gr.update(visible=True), gr.update(visible=False)
    else:
        return "Email already exists. Try logging in.", gr.update(visible=False), gr.update(visible=True)

def navigate_to_login():
    return gr.update(visible=True), gr.update(visible=False)

# Gradio app with popup modal and cart system
def app():
    with gr.Blocks() as demo:
        # Login Page
        with gr.Column(visible=True) as login_section:
            gr.Markdown("# Login Page")
            email = gr.Textbox(label="Email", placeholder="Enter your email")
            password = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
            error_box = gr.Markdown("", visible=False)
            login_btn = gr.Button("Login")
            create_account_btn = gr.Button("Create an Account")

        # Sign-Up Page
        with gr.Column(visible=False) as signup_section:
            gr.Markdown("# Sign Up Page")
            name = gr.Textbox(label="Name", placeholder="Enter your full name")
            phone = gr.Textbox(label="Phone", placeholder="Enter your phone number")
            signup_email = gr.Textbox(label="Email", placeholder="Enter your email")
            signup_password = gr.Textbox(label="Password", placeholder="Enter a password", type="password")
            success_message = gr.Markdown("", visible=False)
            error_message = gr.Markdown("", visible=False)
            submit_btn = gr.Button("Sign Up")
            back_to_login_btn = gr.Button("Back to Login")

        # Preferences and Menu Section
        with gr.Column(visible=False) as preference_section:
            gr.Markdown("## Preferences")
            selected_preference = gr.Radio(
                choices=["All", "Vegetarian", "Halal/Non-Veg", "Guilt-Free"],
                value="All",
                label="Choose a Preference",
            )
            menu_output = gr.HTML(value=filter_menu("All"))
            cart_output = gr.HTML(value="Your cart is empty.", elem_id="floating-cart")
            modal_window = gr.HTML("""
            <div id="modal" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); padding: 20px; width: 80%; max-width: 600px; z-index: 1000; overflow-y: auto;">
                <div style="text-align: right;">
                    <button onclick="closeModal()" style="background: none; border: none; font-size: 20px; cursor: pointer; font-weight: bold;">&times;</button>
                </div>
                <img id="modal-image" style="width: 100%; height: auto; border-radius: 8px; margin-bottom: 15px;" />
                <h2 id="modal-name" style="margin: 0; font-size: 22px; color: #333;"></h2>
                <p id="modal-description" style="margin: 10px 0; font-size: 16px; color: #666;"></p>
                <p id="modal-price" style="font-size: 18px; color: #28a745; font-weight: bold;"></p>
                <label for="extras" style="display: block; font-size: 16px; margin-top: 10px;">Extras:</label>
                <textarea id="special-instructions" placeholder="Add special instructions here..." style="width: 100%; height: 80px; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 10px;"></textarea>
                <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>
            </div>
            """)
            selected_preference.change(filter_menu, inputs=[selected_preference], outputs=[menu_output])

        # Button Actions
        login_btn.click(authenticate_user, inputs=[email, password], outputs=[login_section, preference_section, error_box])
        create_account_btn.click(navigate_to_signup, inputs=[], outputs=[login_section, signup_section])
        submit_btn.click(create_account, inputs=[name, phone, signup_email, signup_password], outputs=[success_message, signup_section, login_section])
        back_to_login_btn.click(navigate_to_login, inputs=[], outputs=[login_section, signup_section])

        # JavaScript for Popup and Cart Management
        gr.HTML("""
        <script>
        let cart = [];
        function openModal(name, image, description, price) {
            const modal = document.getElementById('modal');
            modal.style.display = 'block';
            document.getElementById('modal-image').src = image;
            document.getElementById('modal-name').innerText = name;
            document.getElementById('modal-description').innerText = description;
            document.getElementById('modal-price').innerText = `$${price}`;
        }
        function closeModal() {
            document.getElementById('modal').style.display = 'none';
        }
        function addToCart() {
            const name = document.getElementById('modal-name').innerText;
            const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
            const instructions = document.getElementById('special-instructions').value || "None";
            cart.push({ name, price, instructions });
            alert(`${name} added to cart!`);
            closeModal();
            updateCart();
        }
        function updateCart() {
            let totalBill = 0;
            let cartHTML = '<div style="border: 1px solid #ddd; padding: 10px; border-radius: 8px;">';
            cart.forEach((item, index) => {
                totalBill += item.price;
                cartHTML += `<div style="display: flex; justify-content: space-between; padding: 5px 0;">
                                <span>${item.name}</span>
                                <span>$${item.price.toFixed(2)}</span>
                                <span>Instructions: ${item.instructions}</span>
                                <button onclick="removeFromCart(${index})">Remove</button>
                            </div>`;
            });
            cartHTML += `<div><strong>Total Bill: $${totalBill.toFixed(2)}</strong></div></div>`;
            document.getElementById('floating-cart').innerHTML = cartHTML;
        }
        function removeFromCart(index) {
            cart.splice(index, 1);
            updateCart();
        }
        </script>
        """)

    return demo

if __name__ == "__main__":
    demo = app()
    demo.launch()