import gradio as gr # type: ignore import matplotlib.pyplot as plt # --- LOGIN & SIGN-UP FUNCTIONS --- def community_login(username, password): if username and password: return ( gr.update(visible=False), # Hide intro 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 corporate_login(username, password): if username == "admin" and password == "1234": return ( gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), "✅ 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." 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}\n📍 {zip_code or 'Not provided'}\n" f"🎯 Interests: {', '.join(interests) if interests else 'None'}" ) def logout(): return ( gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), ) # --- MAIN INTERFACE --- with gr.Blocks( title="LiftLocal Login", css=""" body, .gradio-container, .block, .wrap { background-color: #f5f1e6 !important; color: #000000 !important; } #logo { display: flex; justify-content: center; align-items: center; background: transparent !important; border: none !important; box-shadow: none !important; margin: 0px auto 2px auto; padding: 0px !important; } #hero { display: flex; justify-content: center; align-items: center; background: transparent !important; border: none !important; box-shadow: none !important; margin: 25px auto 12px auto; padding: 0 !important; } .navbar { width: 100%; background-color: #efe9d5; display: flex; align-items: center; justify-content: space-between; padding: 10px 40px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); position: relative; } .navbar img { height: 80px; width: auto; } .menu-links { display: flex; gap: 30px; } .menu-links a { text-decoration: none; color: #000000; font-weight: 600; font-size: 16px; transition: 0.3s; } .menu-links a:hover { color: #5a5143; } .logout-btn { background: #ffffff !important; color: #000000 !important; border: 2px solid #000000 !important; border-radius: 8px; padding: 6px 14px; font-size: 15px; cursor: pointer; transition: 0.2s; } .logout-btn:hover { background-color: #333333 !important; border-color: #333333 !important; color: #ffffff !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; } """ ) as demo: # --- INTRO SCREEN --- gr.Image("liftlocall.png", show_label=False, elem_id="logo", height=350) gr.Image("hero_photo.png", show_label=False, elem_id="hero", height=300) gr.Markdown("## LiftLocal unites food access and opportunity, offering education and incentives that empower real, lasting growth in EVERY community we serve.") 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") # --- COMMUNITY DASHBOARD --- with gr.Group(visible=False) as community_dashboard: gr.HTML(""" """) gr.Markdown("

🌿 Community Dashboard

") gr.Markdown("Welcome to LiftLocal! Explore food programs, events, and learning opportunities below.") with gr.Tabs(): with gr.Tab("🥗 Food Resources"): gr.Markdown("### Local Food Assistance Programs") gr.Textbox(label="Search by ZIP Code", placeholder="e.g., 36088") gr.Button("Search") with gr.Tab("📚 Education Resources"): gr.Markdown("### Learn and Grow") gr.Button("Explore Opportunities") with gr.Tab("🎁 Promotions / Rewards"): gr.Markdown("### Earn and Redeem Your LiftPoints") gr.Slider(label="Your LiftPoints", value=50, minimum=0, maximum=100, interactive=False) gr.Button("Redeem Rewards") # --- CORPORATE DASHBOARD --- with gr.Group(visible=False) as corporate_dashboard: gr.HTML(""" """) gr.Markdown("

🏢 Corporate Partner Dashboard

") with gr.Tabs(): with gr.Tab("📊 Reports"): gr.Markdown("### Analytics Overview") with gr.Row(): gr.HTML("
Top 5 ZIPs - Rewards
") gr.HTML("
Top 5 ZIPs - Learning Scores
") # Static example plots zip_codes = ["36088", "36104", "36701", "36801", "35124"] rewards = [45, 25, 50, 35, 30] scores = [88, 65, 92, 74, 80] fig1, ax1 = plt.subplots() ax1.bar(zip_codes, rewards, color="#a89f91") ax1.set_title("Rewards by ZIP Code") fig2, ax2 = plt.subplots() ax2.bar(zip_codes, scores, color="#b3aa99") ax2.set_title("Learning Scores by ZIP") gr.Plot(fig1) gr.Plot(fig2) with gr.Tab("💼 Sponsorships"): gr.Markdown("### Manage sponsorship initiatives and upcoming campaigns here.") sponsorship_idea = gr.Textbox( label="New Sponsorship Idea", placeholder="Describe a potential partnership...", lines=2 ) submit_btn = gr.Button("Submit Proposal") confirmation = gr.Textbox(label="Submission Status", interactive=False) def submit_sponsorship(idea): if idea.strip() == "": return "⚠️ Please describe your sponsorship idea before submitting." return f"✅ Thanks for your idea: \"{idea}\" — our partnerships team will review it soon!" submit_btn.click(fn=submit_sponsorship, inputs=sponsorship_idea, outputs=confirmation) with gr.Tab("🌍 Impact"): gr.Markdown("### Community Impact Overview") gr.Markdown("- **Families Supported:** 2,450\n- **Workshops Completed:** 1,220\n- **Corporate Hours Donated:** 890") # --- COMMUNITY 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)") 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 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], ) # --- LOGOUT + BUTTON LOGIC --- logout_btn = gr.Button(visible=False) logout_btn.click(fn=logout, outputs=[intro_buttons, community_dashboard, corporate_dashboard]) 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 --- if __name__ == "__main__": demo.launch()