Lesson 2 official topic

Humm I don’t know why that happens. But anyway I use HF spaces using the code below and that works:

import gradio as gr
from fastai.vision.all import *
import skimage

learn = load_learner('model.pkl')

labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}
examples = ['female.jpg', 'male.jpg']
enable_queue=True

gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(),enable_queue=enable_queue).launch()

I don’t know if it’s my original code in app.py is somewhat wrong, or it’s just some gradio server error which will disappear when using HF.

1 Like