Spaces:
Runtime error
Runtime error
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../lesson_2.ipynb. | |
# %% auto 0 | |
import gradio as gr | |
__all__ = ['learn_inf', 'labels', 'title', 'description', 'article', | |
'examples', 'interpretation', 'enable_queue', 'predict'] | |
# %% ../../lesson_2.ipynb 0 | |
import fastai | |
# %% ../../lesson_2.ipynb 1 | |
import pandas | |
# %% ../../lesson_2.ipynb 2 | |
from fastai.vision.widgets import * | |
# %% ../../lesson_2.ipynb 3 | |
from fastai.vision.all import * | |
# %% ../../lesson_2.ipynb 4 | |
learn_inf = load_learner("./export.pkl") | |
# %% ../../lesson_2.ipynb 6 | |
labels = learn_inf.dls.vocab | |
# %% ../../lesson_2.ipynb 7 | |
def predict(img): | |
img = PILImage.create(img) | |
pred, pred_idx, probs = learn_inf.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# %% ../../lesson_2.ipynb 8 | |
# %% ../../lesson_2.ipynb 9 | |
title = "Car Classifier" | |
description = "Upload the image of a car to get its type. The model uses the resnet18 trained on a variety of images of cars." | |
article = "<p style='text-align: center'><a href='https://github.com/aar2dee2' target='_blank'>Made by aar2dee2</a></p>" | |
examples = ['car2.jpeg', 'car3.jpeg', 'car4.jpeg', | |
'car5.jpg', 'car6.jpg', 'car7.jpg'] | |
interpretation = 'default' | |
enable_queue = True | |
# %% ../../lesson_2.ipynb 10 | |
gr.Interface( | |
fn=predict, | |
inputs=gr.inputs.Image(shape=(512, 512)), | |
outputs=gr.outputs.Label(num_top_classes=3), | |
title=title, | |
description=description, | |
article=article, | |
examples=examples, | |
interpretation=interpretation, | |
enable_queue=enable_queue).launch() | |