File size: 822 Bytes
3eeb6ce
 
 
 
dfa1677
 
4969232
 
2300679
 
 
 
4969232
0e7055a
 
 
 
 
 
dfa1677
 
 
0e7055a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#import fastbook
#fastbook.setup_book()
#from fastbook import *
from fastai.vision.all import *
import gradio as gr

path = untar_data(URLs.PETS)
dls = ImageDataLoaders.from_name_re(path, get_image_files(path/'images'), pat='(.+)_\d+.jpg', item_tfms=Resize(460), batch_tfms=aug_transforms(size=224, min_scale=0.75))
# learn = vision_learner(dls, models.resnet50, metrics=accuracy)
# learn.fine_tune(1)
# learn.path = Path('.')
# learn.export()
learn = load_learner('export.pkl')
labels = learn.dls.vocab
def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}
    
def greet(name):
    return "Hello " + name + "!!"

gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3)).launch(share=True)