sandrocalzada commited on
Commit
4225814
1 Parent(s): 1a6e45f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -45
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(video_in, image_in_video, image_in_img):
32
- if video_in == None and image_in_video == None and image_in_img == None:
33
- raise gr.Error("Please upload a video or image.")
34
- if image_in_video or image_in_img:
35
- print("image", image_in_video, image_in_img)
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("### Video or Image? WebCam or Upload?""")
51
- with gr.Tab("Video") as tab:
52
- with gr.Row():
53
- with gr.Column():
54
- video_or_file_opt = gr.Radio(["webcam", "upload"], value="webcam",
55
- label="How would you like to upload your video?")
56
- video_in = gr.Video(source="webcam", include_audio=False)
57
- video_or_file_opt.change(fn=lambda s: gr.update(source=s, value=None), inputs=video_or_file_opt,
58
- outputs=video_in, queue=False, show_progress=False)
59
- with gr.Column():
60
- video_out = gr.Video()
61
- run_btn = gr.Button("Run")
62
- run_btn.click(fn=predict, inputs=[video_in], outputs=[video_out])
63
- gr.Examples(fn=predict, examples=[], inputs=[
64
- video_in], outputs=[video_out])
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()