Issues working with gradio

For anyone who gets these errors might help

latest gradio version there is API issues with older code.

  1. AttributeError: module ‘gradio’ has no attribute ‘inputs’

  2. The shape argument in gr.Image(shape=(x,y)) is removed but included in some demos

solutions options

  1. using older version pip install gradio==3.50
  2. code for inputs attribute can easy be changed for example
    gr.inputs.Textbox(…)
    gr.Textbox

for the resize images found example to resize image at The shape argument in gr.Image(shape=(x,y)) is removed but included in some demos · Issue #7619 · gradio-app/gradio · GitHub

def resize_image_pil(img, new_width, new_height):
# Convert to PIL image
img = Image.fromarray(img)
# Get original size
width, height = img.size
# Calculate scale
width_scale = new_width / width
height_scale = new_height / height
scale = min(width_scale, height_scale)
# Resize
resized = img.resize((int(widthscale), int(heightscale)), Image.NEAREST)
# Crop to exact size
resized = resized.crop((0, 0, new_width, new_height))
return PILImage(resized) #my small change to convert it PILImage for send it to the prediction func

references

1 Like