Spaces:
Build error
Build error
TzuShianYang
commited on
Commit
·
9bab5aa
1
Parent(s):
0f97577
Add simple webcam capture
Browse files
app.py
CHANGED
|
@@ -1,7 +1,33 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import zipfile
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def add_image(camera: gr.Image, gallery: gr.Gallery):
|
| 7 |
+
if gallery:
|
| 8 |
+
images = gallery
|
| 9 |
+
images.append(camera)
|
| 10 |
+
return images
|
| 11 |
+
else:
|
| 12 |
+
return [camera]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 16 |
+
with gr.Row():
|
| 17 |
+
with gr.Column():
|
| 18 |
+
camera = gr.Image(type="pil", format="png", webcam_constraints={
|
| 19 |
+
"video": {"width": 640, "height": 640}}, sources="webcam", scale=0)
|
| 20 |
+
catch_btn = gr.Button("Capture", scale=0)
|
| 21 |
+
with gr.Column():
|
| 22 |
+
preview_img = gr.Image(visible=False)
|
| 23 |
+
with gr.Row():
|
| 24 |
+
with gr.Column():
|
| 25 |
+
gallery = gr.Gallery(
|
| 26 |
+
label="Collected images", show_label=False, elem_id="gallery", columns=[10], rows=[4], object_fit="contain", height="auto")
|
| 27 |
+
download_btn = gr.Button("Download", scale=0)
|
| 28 |
+
|
| 29 |
+
catch_btn.click(add_image, [preview_img, gallery], [gallery])
|
| 30 |
+
camera.stream(lambda s: s, camera, preview_img)
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|