File size: 550 Bytes
b15653e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastai.vision.all import *
import gradio as gr

class Classifier:
    def __init__(self, model_path):
        self.learn = load_learner(model_path)

    def predict(self, image):
        pred, pred_idx, probs = self.learn.predict(image)
        return {self.learn.dls.vocab[i]: float(p) for i, p in enumerate(probs)}
    
image = gr.inputs.Image(shape=(128, 128))
label = gr.outputs.Label()
classifer = Classifier(model_path="model.pkl")

interface = gr.Interface(fn=classifer.predict, inputs=image, outputs=label)
interface.launch(inline=False)