from fastai.vision.all import * | |
import pathlib | |
import numpy as np | |
import cv2 | |
from PIL import image | |
plt = platform.system() | |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath | |
learn=load_learner("CatvsDogmodel.pkl") | |
categories=('Cat','Dog') | |
def classify_image(img): | |
pred, idx, probs = learn.predict(img) | |
return dict(zip(categories, map(float,probs))) | |
import gradio as gr | |
image=gr.inputs.Image(shape=(224, 224)) | |
image = cv2.imread(image) | |
Image.open(image) | |
image = image/255 | |
image = np.reshape(image, [1,224,224,3]) | |
label=gr.outputs.Label() | |
intf=gr.Interface(fn=classify_image, inputs=image, outputs=label) | |
intf.launch(inline=False) |