File size: 569 Bytes
5fba393
384db06
33bfc8e
788fbbb
c151ed3
b922c2f
64e76e2
788fbbb
64e76e2
 
bf8d034
788fbbb
 
 
bf8d034
 
788fbbb
 
bf8d034
c151ed3
b922c2f
30dfdfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from huggingface_hub import from_pretrained_fastai
from fastai.vision.all import *
import gradio as gr
from gradio.components import Image
from gradio import Label
from pathlib import Path

model_path = Path("model.pkl")
learner = load_learner(model_path)
labels = learner.dls.vocab


def predict_fn(img):
    pred, pred_idx, probs = learner.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}


gr.Interface(predict_fn,
             Image(shape=(512, 512)),
             outputs=Label(num_top_classes=3),
             ).launch()