Spaces:
Sleeping

File size: 679 Bytes
c409603
 
 
 
 
b8e9bf1
c409603
 
6819cd4
b8e9bf1
 
c409603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
import numpy as np
import time
from fastai.vision.all import *
from pathlib import Path
#import pathlib


path_to_model = Path("resnet50_classifier_0.55valloss")
#temp = pathlib.PosixPath
#pathlib.PosixPath = pathlib.WindowsPath
model = load_learner(str(path_to_model))
model

labels = model.dls.vocab
def classify(img: np.ndarray):
    all_labels = []
    pred_label, idx, proba = model.predict(img)
    return {label:prob for prob,label in zip( proba, labels )}

im = gr.Image(height=256,width= 100, image_mode='L', sources="upload")
#setup the interface
iface = gr.Interface(
    fn = classify,
    inputs = im,
    outputs = gr.Label()
)
iface.launch()