File size: 1,320 Bytes
8ee9448
bfab212
 
8ee9448
bfab212
8ee9448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409042d
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
42
43
44
45
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)