minimal / app.py
xeeshan's picture
Changed to model pth since huggingface does not allow pkl anymore
fd1b98b
#import gradio as gr
#def greet(name):
# return "Hello " + name + "!!"
#
#demo = gr.Interface(fn=greet, inputs="text", outputs="text")
#demo.launch()
# second time used this only but huggingface doesn't like it so moving to a different method
#learner=load_learner('model.pkl')
from fastai.vision.all import *
import gradio as gr
def is_cat(x): return x[0].isupper()
dls = ImageDataLoaders.from_lists('.', fnames=['cat.jpeg','dog.jpeg'], labels=['cat','dog'], vocab=['cat', 'dog'])
learner = vision_learner(dls, resnet18, metrics=error_rate)
learner.load('model')
categories = ['Dog','Cat']
def classify_image(img):
pred,pred_idx,probs = learner.predict(img)
return dict(zip(categories, map(float,probs)))
image=gr.Image()
#image=gr.Image(shape=(192,192))
label=gr.Label()
examples=['dog.jpeg', 'cat.jpeg','dogcat.jpeg']
titleText="Dog vs Cat Classifier"
descriptionText="Upload an image of a dog or a cat to predict the probabilities of each class."
intf=gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples,
title=titleText, description=descriptionText)
intf.launch()