File size: 504 Bytes
e8fc84d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from fastai.vision.all import *
from pathlib import Path
import pathlib
hugging_face = True
if not hugging_face:
    temp = pathlib.PosixPath
    pathlib.PosixPath = pathlib.WindowsPath
learn = load_learner(Path("./model.pkl"))
def predict_image(image):
    pred, pred_idx, probs = learn.predict(image)
    return pred, probs[pred_idx].item()

app = gr.Interface(fn=predict_image, 
    inputs=gr.Image(type="pil"), 
    outputs=[gr.Label(), gr.Number()],
    live=True
)

app.launch()