Spaces:
Build error
Build error
TzuShianYang
commited on
Commit
·
c6bd672
1
Parent(s):
27e2fc3
Fix warning for webcam down and info for zip file
Browse files
app.py
CHANGED
|
@@ -4,12 +4,15 @@ import datetime
|
|
| 4 |
|
| 5 |
|
| 6 |
def add_image(camera, gallery):
|
| 7 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
images = gallery
|
| 9 |
images.append(camera)
|
| 10 |
return images
|
| 11 |
-
else:
|
| 12 |
-
return [camera]
|
| 13 |
|
| 14 |
|
| 15 |
def zip_gallery(gallery):
|
|
@@ -26,46 +29,47 @@ def zip_gallery(gallery):
|
|
| 26 |
count = count + 1
|
| 27 |
except FileNotFoundError:
|
| 28 |
print("Error Occurred!")
|
|
|
|
| 29 |
finally:
|
| 30 |
zf.close()
|
|
|
|
| 31 |
|
| 32 |
return gr.DownloadButton("Download", value=new_zip_name, visible=True)
|
| 33 |
|
| 34 |
|
| 35 |
with gr.Blocks(fill_height=True) as demo:
|
| 36 |
with gr.Row():
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
preview_img = gr.Image(visible=False)
|
| 43 |
-
gr.Markdown(
|
| 44 |
-
"""
|
| 45 |
-
# How to Use
|
| 46 |
-
|
| 47 |
-
1. Open Camera on left side, then click "Record" button on the camera screen
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
with gr.Row():
|
| 68 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
gallery = gr.Gallery(
|
| 70 |
label="Collected images", show_label=False, elem_id="gallery", columns=[10], rows=[4], object_fit="contain", height="auto")
|
| 71 |
zip_btn = gr.Button("Zip file")
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def add_image(camera, gallery):
|
| 7 |
+
if camera is None:
|
| 8 |
+
gr.Warning("No Camera Recording!")
|
| 9 |
+
return
|
| 10 |
+
if gallery is None:
|
| 11 |
+
return [camera]
|
| 12 |
+
else:
|
| 13 |
images = gallery
|
| 14 |
images.append(camera)
|
| 15 |
return images
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def zip_gallery(gallery):
|
|
|
|
| 29 |
count = count + 1
|
| 30 |
except FileNotFoundError:
|
| 31 |
print("Error Occurred!")
|
| 32 |
+
gr.Warning("Zip Error!")
|
| 33 |
finally:
|
| 34 |
zf.close()
|
| 35 |
+
gr.Info(f"Zip Complete. Name: {new_zip_name}")
|
| 36 |
|
| 37 |
return gr.DownloadButton("Download", value=new_zip_name, visible=True)
|
| 38 |
|
| 39 |
|
| 40 |
with gr.Blocks(fill_height=True) as demo:
|
| 41 |
with gr.Row():
|
| 42 |
+
gr.Markdown(
|
| 43 |
+
"""
|
| 44 |
+
# How to Use
|
| 45 |
+
|
| 46 |
+
1. Open Camera on left side, then click "Record" button on the camera screen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
2. Click "Capture" button to capture image to gallery
|
| 49 |
|
| 50 |
+
3. After capture all image, click "Zip file" button to zip images
|
| 51 |
|
| 52 |
+
4. Download zip file by clicking "Download" button showed below
|
| 53 |
|
| 54 |
+
# 如何使用
|
| 55 |
+
|
| 56 |
+
1. 點擊左側開啟攝影機,並按下"Record"按鈕讓攝影機能夠進行擷取
|
| 57 |
|
| 58 |
+
2. 點擊"Capture"按鈕,影像就會被擷取到下方的欄位中
|
| 59 |
|
| 60 |
+
3. 擷取影像完畢後,點擊下方的"Zip file"按鈕將影像打包並壓縮
|
| 61 |
|
| 62 |
+
4. 按下隨後出現的"Download"按鈕就能下載打包好的壓縮檔
|
| 63 |
+
|
| 64 |
+
"""
|
| 65 |
+
)
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column():
|
| 68 |
+
camera = gr.Image(type="pil", format="png", webcam_constraints={
|
| 69 |
+
"video": {"width": 640, "height": 640}}, sources="webcam", mirror_webcam=False, scale=0)
|
| 70 |
+
catch_btn = gr.Button("Capture", scale=0)
|
| 71 |
+
with gr.Column():
|
| 72 |
+
preview_img = gr.Image(visible=False)
|
| 73 |
gallery = gr.Gallery(
|
| 74 |
label="Collected images", show_label=False, elem_id="gallery", columns=[10], rows=[4], object_fit="contain", height="auto")
|
| 75 |
zip_btn = gr.Button("Zip file")
|