LiftLocaldemo / app.py
kcooley03's picture
Rename app file back to app.py for Hugging Face deployment
35a0478
Raw History Blame Contribute Delete
9.51 kB
import gradio as gr
# --- LOGIN & SIGN-UP FUNCTIONS ---
def community_login(username, password):
if username and password:
# Hide intro screen + community portal, show dashboard
return (
gr.update(visible=False), # Hide intro_buttons
gr.update(visible=False), # Hide community_portal
gr.update(visible=True), # Show community_dashboard
f"βœ… Welcome back, {username}!"
)
return gr.update(), gr.update(), gr.update(), "⚠️ Please enter both username and password."
def community_signup(first, last, email, zip_code, interests):
if not (first and last and email):
return "⚠️ Please fill in all required fields (First, Last, Email)."
return (
f"πŸŽ‰ Thanks for signing up, {first} {last}!\n"
f"πŸ“§ Email: {email}\n"
f"πŸ“ Zip Code: {zip_code or 'Not provided'}\n"
f"🎯 Interests: {', '.join(interests) if interests else 'None selected'}\n"
"Welcome to LiftLocal!"
)
def corporate_login(username, password):
if username == "admin" and password == "1234":
return (
gr.update(visible=False), # Hide intro_buttons
gr.update(visible=False), # Hide corporate_portal
gr.update(visible=True), # Show corporate_dashboard
"βœ… Corporate access granted. Welcome!"
)
elif username and password:
return (
gr.update(visible=False),
gr.update(visible=False),
gr.update(visible=True),
f"Hello {username}! (Demo login only)"
)
return gr.update(), gr.update(), gr.update(), "⚠️ Please enter both username and password."
# βœ… FIX: logout returns the updates, not used inline
def logout():
return (
gr.update(visible=True), # Show intro
gr.update(visible=False), # Hide community dashboard
gr.update(visible=False) # Hide corporate dashboard
)
# --- MAIN INTERFACE ---
with gr.Blocks(
title="LiftLocal Login",
css="""
body, .gradio-container, .block, .wrap {
background-color: #f5f1e6 !important;
color: #000000 !important;
}
#logo, #logo * {
border: none !important;
box-shadow: none !important;
outline: none !important;
background: none !important;
}
#logo {
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto 10px auto;
padding: 0 !important;
}
.gr-image {
background: transparent !important;
box-shadow: none !important;
border: none !important;
}
img {
background: transparent !important;
border: none !important;
box-shadow: none !important;
}
#user_button, #employee_button {
font-size: 18px;
padding: 10px 18px;
margin: 10px;
background-color: #ffffff;
border: 2px solid #b0a999;
border-radius: 10px;
color: #000000;
transition: all 0.3s ease;
width: 180px;
}
#user_button:hover, #employee_button:hover {
background-color: #e0d6c3;
border-color: #8a7f6b;
transform: scale(1.05);
}
h1, h2, h3, p {
text-align: center !important;
color: #000000 !important;
}
label, .gr-label, .gradio-input label, .wrap label, .form label {
color: #000000 !important;
font-weight: 600 !important;
text-align: left !important;
}
input, textarea, select {
background-color: #ffffff !important;
color: #000000 !important;
border: 1.5px solid #b0a999 !important;
border-radius: 6px !important;
font-size: 16px !important;
caret-color: #000000 !important;
}
input::placeholder, textarea::placeholder {
color: #7a7a7a !important;
opacity: 1 !important;
}
input:focus, textarea:focus, select:focus {
border-color: #8a7f6b !important;
outline: none !important;
box-shadow: 0 0 5px rgba(138, 127, 107, 0.4) !important;
}
.block {
display: flex;
flex-direction: column;
align-items: center;
}
.gradio-container .form {
background-color: transparent !important;
box-shadow: none !important;
}
.tabs {
background-color: transparent !important;
}
.logout-btn {
position: absolute;
top: 15px;
right: 20px;
background: #ffffff;
border: 2px solid #b0a999;
border-radius: 8px;
padding: 6px 14px;
font-size: 15px;
cursor: pointer;
transition: 0.3s;
}
.logout-btn:hover {
background-color: #e0d6c3;
}
"""
) as demo:
# --- INTRO SECTION ---
gr.Image("liftlocall.png", show_label=False, show_download_button=False, elem_id="logo", height=300)
gr.Markdown("<h2><b>LiftLocal</b></h2>")
gr.Markdown("## Login Portal")
gr.Markdown("---")
gr.Markdown("### Are you joining as a community user or an organization partner?")
with gr.Row() as intro_buttons:
user_btn = gr.Button("πŸ‘€ Community User", elem_id="user_button")
corp_btn = gr.Button("🏒 Organization Partner", elem_id="employee_button")
# --- DASHBOARDS ---
with gr.Group(visible=False) as community_dashboard:
gr.Markdown("<h2>🌿 Community Dashboard</h2>")
gr.Markdown("Welcome to LiftLocal! Explore food programs, local events, and learning resources.")
logout_btn1 = gr.Button("Logout", elem_classes=["logout-btn"])
with gr.Group(visible=False) as corporate_dashboard:
gr.Markdown("<h2>🏒 Corporate Partner Dashboard</h2>")
gr.Markdown("Manage partnerships, sponsorships, and community projects.")
logout_btn2 = gr.Button("Logout", elem_classes=["logout-btn"])
# --- COMMUNITY LOGIN PORTAL ---
with gr.Group(visible=False) as community_portal:
gr.Markdown("## πŸ‘€ Community User Portal")
with gr.Tab("Login"):
c_user = gr.Textbox(label="", placeholder="Enter your username or email")
c_pass = gr.Textbox(label="", type="password", placeholder="Enter your password")
c_button = gr.Button("Login")
c_output = gr.Textbox(label="Login Message", interactive=False)
c_button.click(
fn=community_login,
inputs=[c_user, c_pass],
outputs=[intro_buttons, community_portal, community_dashboard, c_output]
)
with gr.Tab("Sign Up"):
f_name = gr.Textbox(label="", placeholder="Enter your first name")
l_name = gr.Textbox(label="", placeholder="Enter your last name")
email = gr.Textbox(label="", placeholder="Enter your email")
zip_code = gr.Textbox(label="", placeholder="Enter your zip code (optional) e.g., 36088")
interests = gr.CheckboxGroup(
["Cooking", "Budgeting", "Job Skills", "Health & Wellness", "Technology"],
label="Learning Interests",
interactive=True,
)
s_button = gr.Button("Sign Up")
s_output = gr.Textbox(label="Registration Result", interactive=False)
s_button.click(
fn=community_signup,
inputs=[f_name, l_name, email, zip_code, interests],
outputs=s_output,
)
# --- CORPORATE LOGIN PORTAL ---
with gr.Group(visible=False) as corporate_portal:
gr.Markdown("## 🏒 Corporate Partner Login")
corp_user = gr.Textbox(label="", placeholder="Enter your username")
corp_pass = gr.Textbox(label="", type="password", placeholder="Enter your password")
corp_button = gr.Button("Login")
corp_output = gr.Textbox(label="Login Status", interactive=False)
corp_button.click(
fn=corporate_login,
inputs=[corp_user, corp_pass],
outputs=[intro_buttons, corporate_portal, corporate_dashboard, corp_output]
)
# βœ… Proper logout buttons now reference the logout() function
logout_btn1.click(fn=logout, outputs=[intro_buttons, community_dashboard, corporate_dashboard])
logout_btn2.click(fn=logout, outputs=[intro_buttons, community_dashboard, corporate_dashboard])
# --- BUTTON LOGIC ---
def open_user_portal():
return gr.update(visible=True), gr.update(visible=False)
def open_corporate_portal():
return gr.update(visible=False), gr.update(visible=True)
user_btn.click(fn=open_user_portal, outputs=[community_portal, corporate_portal])
corp_btn.click(fn=open_corporate_portal, outputs=[community_portal, corporate_portal])
# --- Run app ---
import gradio as gr
def greet(name):
return f"Hello {name}! Welcome to LiftLocal."
demo = gr.Interface(
fn=greet,
inputs=gr.Textbox(label="Enter your name"),
outputs=gr.Textbox(label="Greeting"),
title="LiftLocal Demo",
description="A simple Gradio app example."
)
if __name__ == "__main__":
demo.launch()