Spaces:
Running
Running
sandrocalzada
commited on
Commit
•
4225814
1
Parent(s):
1a6e45f
Update app.py
Browse files
app.py
CHANGED
@@ -28,16 +28,11 @@ def predict_gender(image):
|
|
28 |
return "Male" if prediction[0] < 0.5 else "Female"
|
29 |
|
30 |
|
31 |
-
def predict(
|
32 |
-
if
|
33 |
-
raise gr.Error("Please upload
|
34 |
-
|
35 |
-
|
36 |
-
image = image_in_video or image_in_img
|
37 |
-
return image
|
38 |
-
|
39 |
-
return video_in
|
40 |
-
|
41 |
|
42 |
def toggle(choice):
|
43 |
if choice == "webcam":
|
@@ -45,42 +40,23 @@ def toggle(choice):
|
|
45 |
else:
|
46 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
47 |
|
48 |
-
|
49 |
with gr.Blocks() as blocks:
|
50 |
-
gr.Markdown("###
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
with gr.Tab("Image"):
|
67 |
-
with gr.Row():
|
68 |
-
with gr.Column():
|
69 |
-
image_or_file_opt = gr.Radio(["webcam", "file"], value="webcam",
|
70 |
-
label="How would you like to upload your image?")
|
71 |
-
image_in_video = gr.Image(source="webcam", type="filepath")
|
72 |
-
image_in_img = gr.Image(
|
73 |
-
source="upload", visible=False, type="filepath")
|
74 |
-
|
75 |
-
image_or_file_opt.change(fn=toggle, inputs=[image_or_file_opt],
|
76 |
-
outputs=[image_in_video, image_in_img], queue=False, show_progress=False)
|
77 |
-
with gr.Column():
|
78 |
-
image_out = gr.Image()
|
79 |
-
run_btn = gr.Button("Run")
|
80 |
-
run_btn.click(fn=predict, inputs=[
|
81 |
-
image_in_img, image_in_video], outputs=[image_out])
|
82 |
-
gr.Examples(fn=predict, examples=[], inputs=[
|
83 |
-
image_in_img, image_in_video], outputs=[image_out])
|
84 |
|
85 |
blocks.queue()
|
86 |
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 upload an image.")
|
34 |
+
image = image_in_video or image_in_img
|
35 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def toggle(choice):
|
38 |
if choice == "webcam":
|
|
|
40 |
else:
|
41 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
42 |
|
|
|
43 |
with gr.Blocks() as blocks:
|
44 |
+
gr.Markdown("### WebCam or Upload?")
|
45 |
+
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
image_or_file_opt = gr.Radio(["webcam", "file"], value="webcam",
|
49 |
+
label="How would you like to upload your image?")
|
50 |
+
image_in_video = gr.Image(source="webcam", type="filepath")
|
51 |
+
image_in_img = gr.Image(source="upload", visible=False, type="filepath")
|
52 |
+
|
53 |
+
image_or_file_opt.change(fn=toggle, inputs=[image_or_file_opt],
|
54 |
+
outputs=[image_in_video, image_in_img], queue=False, show_progress=False)
|
55 |
+
with gr.Column():
|
56 |
+
image_out = gr.Image()
|
57 |
+
run_btn = gr.Button("Run")
|
58 |
+
run_btn.click(fn=predict, inputs=[image_in_img, image_in_video], outputs=[image_out])
|
59 |
+
gr.Examples(fn=predict, examples=[], inputs=[image_in_img, image_in_video], outputs=[image_out])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
blocks.queue()
|
62 |
blocks.launch()
|