Spaces:
Sleeping
Sleeping
File size: 9,506 Bytes
4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 8efa66c 4405280 13e742a 4405280 | 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | 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()
|