File size: 626 Bytes
53f7f13
711e417
 
53f7f13
711e417
53f7f13
711e417
 
 
 
 
 
 
 
14148cc
711e417
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
from fastai.vision.all import load_learner
from PIL import Image

model = load_learner('./export.pkl')  

def classify_image(img):
    # Convert the image to a format the model expects
    img = Image.fromarray(img.astype('uint8'), 'RGB')
    # Make a prediction
    pred, idx, probs = model.predict(img)
    # Return the result
    return {model.dls.vocab[i]: float(probs[i]) for i in range(len(model.dls.vocab))}

demo = gr.Interface(fn=classify_image, inputs=gr.Image(label = 'Upload an image of a dung beetle, a dolphin, or an elephant!'), outputs="label")

if __name__ == "__main__":
    demo.launch()