Spaces:
Sleeping
Sleeping
danielecelsa
commited on
Commit
·
5d03732
1
Parent(s):
a830736
final
Browse files- app.py +30 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categorie', 'img', 'lbl', 'esempi', 'intfc', 'is_cat', 'classify_images']
|
5 |
+
|
6 |
+
# %% app.ipynb 2
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
+
|
12 |
+
# %% app.ipynb 4
|
13 |
+
learn = load_learner('model.pkl')
|
14 |
+
|
15 |
+
# %% app.ipynb 6
|
16 |
+
categorie = ('Cane', 'Gatto')
|
17 |
+
|
18 |
+
def classify_images(immagine):
|
19 |
+
immagine = immagine.resize((512, 512)) # Resize to 512x512 -> non credo funzioni, serviva perche shape(192, 192) non si usa più
|
20 |
+
immagine = PILImage.create(immagine) # stesso motivo di sopra
|
21 |
+
pred, idx, probs = learn.predict(immagine)
|
22 |
+
return dict(zip(categorie, map(float, probs)))
|
23 |
+
|
24 |
+
# %% app.ipynb 8
|
25 |
+
img = gr.Image(type="pil", image_mode="RGB") # stesso motivo di sopra
|
26 |
+
lbl = gr.Label()
|
27 |
+
esempi = ['dog.jpg', 'cat.jpg', 'elephant.jpg']
|
28 |
+
|
29 |
+
intfc = gr.Interface(fn=classify_images, inputs=img, outputs=lbl, examples=esempi)
|
30 |
+
intfc.launch(inline=False, share=True)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|