Spaces:
Sleeping

CNN / app.py
arsath01's picture
Upload app.py
b8e9bf1 verified
Raw History Blame Contribute Delete
679 Bytes
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()