Hello, I made an object detection model and I managed to display predictions in Gradio using a webcam or uploading a picture, but in separated gradio apps, using as input:
input_1 = gr.inputs.Image(type='pil', label="Original Image", source="upload")
or
input_2 = gr.inputs.Image(type='pil', label="Original Image", source="webcam")
Iβd like to have both options in the same app, so users would be able to choose between uploading a picture or making a picture using the webcam. I tried to pass both inputs as a list:
inputs = [input_1, input_2]
When I try to make the prediction the output image shows an error message. I tried setting the optional property in the inputs as True, but it still shows the error.
The interface goes like this:
input = gr.inputs.Image(type='pil', label="Original Image", source="upload", optional=True)
input_2 = gr.inputs.Image(type='pil', label="Original Image", source="webcam", optional=True)
inputs = [input, input_2]
outputs = gr.outputs.Image(type="pil", label="Output Image")
title = "Object detection with Yolov5"
gr.Interface(predict,
inputs,
outputs,
title=title,
theme="huggingface").launch(enable_queue=True)
And the predict function goes like this:
def predict(im, size=640):
g = (size / max(im.size)) # gain
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
results = model(im) # inference
results.render() # updates results.imgs with boxes and labels
return Image.fromarray(results.imgs[0])
Is there a way to make this or I should just keep the inputs as separated apps?
Thanks in advance