import gradio as gr # ====================== # FUNCTIONS # ====================== def monitor(image): if image is None: return None, "Waiting for camera..." return image, "SAFE ✅" def grocery_calc(goal): current = 62 return f"Estimated Protein Intake: {current}g / {goal}g" # ====================== # UI # ====================== with gr.Blocks(title="Kitchen AI Dashboard") as demo: gr.Markdown("# 🍳 AI Kitchen Safety & Smart Grocery Dashboard") with gr.Row(): # -------- SIDEBAR ---------- with gr.Column(scale=1): gr.Markdown("## Navigation") overview_btn = gr.Button("Overview") monitor_btn = gr.Button("Live Monitor") grocery_btn = gr.Button("Smart Grocery") # -------- MAIN PANEL ---------- with gr.Column(scale=4): content = gr.Markdown( "Welcome to AI Kitchen Monitoring System" ) cam = gr.Image( sources=["webcam"], visible=False, label="Kitchen Camera" ) status = gr.Textbox( label="Hazard Status", visible=False ) protein = gr.Slider( 50, 150, value=100, label="Daily Protein Goal", visible=False ) grocery_output = gr.Textbox( label="Protein Analysis", visible=False ) # ====================== # NAVIGATION FUNCTIONS # ====================== def show_overview(): return ( "## Overview\nAI Kitchen Safety + Smart Grocery System", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), ) def show_monitor(): return ( "## Live Kitchen Monitoring", gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), ) def show_grocery(): return ( "## Smart Grocery Intelligence", gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), ) # ====================== # EVENTS (INSIDE BLOCKS ✅) # ====================== overview_btn.click( show_overview, outputs=[content, cam, status, protein, grocery_output], ) monitor_btn.click( show_monitor, outputs=[content, cam, status, protein, grocery_output], ) grocery_btn.click( show_grocery, outputs=[content, cam, status, protein, grocery_output], ) cam.change( monitor, inputs=cam, outputs=[cam, status], ) protein.change( grocery_calc, inputs=protein, outputs=grocery_output, ) # ====================== # LAUNCH # ====================== demo.launch()