Spaces:
Runtime error
Runtime error
Ilija Eftimov
commited on
Commit
·
8ee9448
1
Parent(s):
bfab212
add everyhting
Browse files- app.py +41 -4
- campanelle/1.jpg +0 -0
- campanelle/2.jpg +0 -0
- campanelle/3.jpg +0 -0
- fusilli/1.jpg +0 -0
- fusilli/2.jpg +0 -0
- fusilli/3.jpg +0 -0
- macaroni/1.jpg +0 -0
- macaroni/3.jpg +0 -0
- model.pkl +3 -0
app.py
CHANGED
@@ -1,7 +1,44 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
+
learn = load_learner("model.pkl")
|
|
|
5 |
|
6 |
+
labels = learn.dls.vocab
|
7 |
+
def classify_image(img):
|
8 |
+
pred, idx, probs = learn.predict(img)
|
9 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
10 |
+
|
11 |
+
image = gr.inputs.Image(shape=(192,192))
|
12 |
+
label = gr.outputs.Label()
|
13 |
+
|
14 |
+
examples = []
|
15 |
+
for t in templates:
|
16 |
+
for n in range(1,4):
|
17 |
+
examples.append(f"campanelle/{n}.jpg")
|
18 |
+
examples.append(f"macaroni/{n}.jpg")
|
19 |
+
examples.append(f"fusilli/{n}.jpg")
|
20 |
+
|
21 |
+
title = "Pasta Recognition"
|
22 |
+
|
23 |
+
description = """
|
24 |
+
Pasta is delicious, but there are too many pasta types to remember. This app will help you
|
25 |
+
recall the name of the pasta whose image you'll upload.
|
26 |
+
|
27 |
+
Under the hood it's a pasta classifier, built using Fast.ai by fine-tuning the
|
28 |
+
`convnext_base_in22ft1k` model. It supports only the followig pasta types:
|
29 |
+
|
30 |
+
* Campanelle
|
31 |
+
* Ditalini
|
32 |
+
* Fettuccine
|
33 |
+
* Fusilli
|
34 |
+
* Linguine
|
35 |
+
* Macaroni
|
36 |
+
* Pappardelle
|
37 |
+
|
38 |
+
The model's accuracy is ~82%.
|
39 |
+
|
40 |
+
The notebook used to train the model can be seen [in Google Colab](https://colab.research.google.com/drive/1NM6BvRkV7xDlnncFqVRGxxg0GFtqpVgT?usp=sharing).
|
41 |
+
"""
|
42 |
+
|
43 |
+
iface = gr.Interface(fn=classify_image, inputs=image, outputs=gr.outputs.Label(), examples=examples, title=title, description=description)
|
44 |
+
iface.launch(inline=False)
|
campanelle/1.jpg
ADDED
![]() |
campanelle/2.jpg
ADDED
![]() |
campanelle/3.jpg
ADDED
![]() |
fusilli/1.jpg
ADDED
![]() |
fusilli/2.jpg
ADDED
![]() |
fusilli/3.jpg
ADDED
![]() |
macaroni/1.jpg
ADDED
![]() |
macaroni/3.jpg
ADDED
![]() |
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0576c8d7c57113c5f23dc3028fb900345e2a02bca7e6453f7f12ab76f19e4ad3
|
3 |
+
size 114641385
|