File size: 1,140 Bytes
270c814 fd1b98b 270c814 dd0035c 270c814 fd1b98b 270c814 dd0035c 270c814 |
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 32 33 34 35 36 37 38 39 40 41 |
#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() |