Spaces:
Running
Running
sandrocalzada
commited on
Commit
•
7702267
1
Parent(s):
a2d57e1
Update app.py
Browse files
app.py
CHANGED
@@ -28,23 +28,37 @@ def predict_gender(image):
|
|
28 |
return "Male" if prediction[0] < 0.5 else "Female"
|
29 |
|
30 |
|
31 |
-
def predict(image_in_video):
|
32 |
-
if image_in_video == None:
|
33 |
-
raise gr.Error("Please capture an image using the webcam.")
|
34 |
-
|
|
|
35 |
|
36 |
with gr.Blocks() as blocks:
|
37 |
-
gr.Markdown("### Capture Image Using WebCam")
|
38 |
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
|
|
|
|
41 |
image_in_video = gr.Image(source="webcam", type="filepath")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
with gr.Column():
|
43 |
image_out = gr.Image()
|
44 |
-
|
45 |
run_btn = gr.Button("Run")
|
46 |
-
run_btn.click(fn=predict, inputs=[image_in_video], outputs=[image_out])
|
47 |
-
gr.Examples(fn=predict, examples=[], inputs=[image_in_video], outputs=[image_out])
|
48 |
|
49 |
blocks.queue()
|
50 |
blocks.launch()
|
|
|
28 |
return "Male" if prediction[0] < 0.5 else "Female"
|
29 |
|
30 |
|
31 |
+
def predict(image_in_video, image_in_img):
|
32 |
+
if image_in_video == None and image_in_img == None:
|
33 |
+
raise gr.Error("Please capture an image using the webcam or upload an image.")
|
34 |
+
image = image_in_video or image_in_img
|
35 |
+
return image
|
36 |
|
37 |
with gr.Blocks() as blocks:
|
38 |
+
gr.Markdown("### Capture Image Using WebCam or Upload")
|
39 |
|
40 |
with gr.Row():
|
41 |
with gr.Column():
|
42 |
+
image_or_file_opt = gr.Radio(["webcam", "file"], value="webcam",
|
43 |
+
label="How would you like to upload your image?")
|
44 |
image_in_video = gr.Image(source="webcam", type="filepath")
|
45 |
+
image_in_img = gr.Image(source="upload", visible=False, type="filepath")
|
46 |
+
|
47 |
+
# Update visibility based on selection
|
48 |
+
def toggle(choice):
|
49 |
+
if choice == "webcam":
|
50 |
+
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
51 |
+
else:
|
52 |
+
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
53 |
+
|
54 |
+
image_or_file_opt.change(fn=toggle, inputs=[image_or_file_opt],
|
55 |
+
outputs=[image_in_video, image_in_img], queue=False, show_progress=False)
|
56 |
with gr.Column():
|
57 |
image_out = gr.Image()
|
58 |
+
|
59 |
run_btn = gr.Button("Run")
|
60 |
+
run_btn.click(fn=predict, inputs=[image_in_img, image_in_video], outputs=[image_out])
|
61 |
+
gr.Examples(fn=predict, examples=[], inputs=[image_in_img, image_in_video], outputs=[image_out])
|
62 |
|
63 |
blocks.queue()
|
64 |
blocks.launch()
|