Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
|
5 |
+
from fastbook import *
|
6 |
+
from fastai.vision.widgets import *
|
7 |
+
import os
|
8 |
+
|
9 |
+
|
10 |
+
# In[6]:
|
11 |
+
|
12 |
+
|
13 |
+
learn = load_learner('export.pkl')
|
14 |
+
|
15 |
+
|
16 |
+
# In[7]:
|
17 |
+
|
18 |
+
|
19 |
+
labels = learn.dls.vocab
|
20 |
+
def predict(img):
|
21 |
+
img = PILImage.create(img)
|
22 |
+
pred,pred_idx,probs = learn.predict(img)
|
23 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
24 |
+
|
25 |
+
|
26 |
+
# In[18]:
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
# In[19]:
|
31 |
+
|
32 |
+
|
33 |
+
import gradio as gr
|
34 |
+
|
35 |
+
title = "Pet Breed Classifier"
|
36 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
37 |
+
|
38 |
+
gr.Interface(fn=predict,
|
39 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
40 |
+
title = "?תפוח או עגבניה",
|
41 |
+
description = "A fruite classifier trained on images from the internet with fastai. Created as a demo for Gradio and HuggingFace Spaces.",
|
42 |
+
interpretation='default',
|
43 |
+
outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)
|
44 |
+
|
45 |
+
|
46 |
+
# In[ ]:
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|