| import gradio as gr | |
| # Function to display webcam image on canvas | |
| def display_webcam_image(img): | |
| return img | |
| # Gradio app interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Webcam Capture and Display") | |
| # Webcam component | |
| webcam = gr.Image(source="webcam", label="Webcam Capture", streaming=True) | |
| # Canvas to display captured image | |
| canvas = gr.Image(label="Captured Image") | |
| # Button to capture image from webcam and display on canvas | |
| capture_button = gr.Button("Capture Image") | |
| capture_button.click(fn=display_webcam_image, inputs=webcam, outputs=canvas) | |
| # Launch the app | |
| demo.launch() |