Ilija Eftimov
add share=True to launch
409042d
raw
history blame
1.32 kB
from fastai.vision.all import *
import gradio as gr
learn = load_learner("model.pkl")
labels = learn.dls.vocab
def classify_image(img):
pred, idx, probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = []
for t in templates:
for n in range(1,4):
examples.append(f"campanelle/{n}.jpg")
examples.append(f"macaroni/{n}.jpg")
examples.append(f"fusilli/{n}.jpg")
title = "Pasta Recognition"
description = """
Pasta is delicious, but there are too many pasta types to remember. This app will help you
recall the name of the pasta whose image you'll upload.
Under the hood it's a pasta classifier, built using Fast.ai by fine-tuning the
`convnext_base_in22ft1k` model. It supports only the followig pasta types:
* Campanelle
* Ditalini
* Fettuccine
* Fusilli
* Linguine
* Macaroni
* Pappardelle
The model's accuracy is ~82%.
The notebook used to train the model can be seen [in Google Colab](https://colab.research.google.com/drive/1NM6BvRkV7xDlnncFqVRGxxg0GFtqpVgT?usp=sharing).
"""
iface = gr.Interface(fn=classify_image, inputs=image, outputs=gr.outputs.Label(), examples=examples, title=title, description=description)
iface.launch(inline=False, share=True)