File size: 553 Bytes
53f7f13
711e417
 
53f7f13
711e417
53f7f13
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="image", outputs="label")

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