Raumkommander commited on
Commit
aa4ed98
·
verified ·
1 Parent(s): 758c1a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -1,25 +1,17 @@
1
  import gradio as gr
2
- import cv2
3
- import numpy as np
4
- from PIL import Image
5
 
6
- def video_stream():
7
- """Captures video feed from webcam and outputs the same stream to a different canvas."""
8
- cap = cv2.VideoCapture(0)
9
- while cap.isOpened():
10
- ret, frame = cap.read()
11
- if not ret:
12
- break
13
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
14
- yield Image.fromarray(frame)
15
- cap.release()
16
 
17
- # Create Gradio App
18
- with gr.Blocks() as demo:
19
- gr.Markdown("## 🎥 Webcam Stream with Output to a Separate Canvas")
20
- webcam_feed = gr.Video(label="Live Webcam", format="mp4", streaming=True)
21
- canvas_output = gr.Image(label="Canvas - Output Stream")
22
- start_button = gr.Button("Start Streaming")
23
- start_button.click(fn=video_stream, inputs=[], outputs=[canvas_output])
24
 
25
- demo.launch(share=True)
 
 
1
  import gradio as gr
 
 
 
2
 
3
+ # Define the function to process the webcam input
4
+ def capture_image(image):
5
+ # You can process the image if you want. Here, we just return it.
6
+ return image
 
 
 
 
 
 
7
 
8
+ # Create the Gradio interface
9
+ interface = gr.Interface(
10
+ fn=capture_image, # Function to process the image
11
+ inputs=gr.Image(source="webcam"), # Capture webcam image
12
+ outputs=gr.Image(), # Display the captured image
13
+ live=True # Make it responsive
14
+ )
15
 
16
+ # Launch the interface
17
+ interface.launch()