let's deploy to huggingface spaces
Browse files
app.py
CHANGED
@@ -1,7 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: is_a_cat.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'labels', 'is_cat', 'predict']
|
5 |
+
|
6 |
+
# %% is_a_cat.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
+
|
12 |
+
# %% is_a_cat.ipynb 2
|
13 |
+
learn = load_learner('model.pkl')
|
14 |
+
|
15 |
+
# %% is_a_cat.ipynb 3
|
16 |
+
labels = learn.dls.vocab
|
17 |
+
def predict(img):
|
18 |
+
img = PILImage.create(img)
|
19 |
+
pred,pred_idx,probs = learn.predict(img)
|
20 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
21 |
|
22 |
+
# %% is_a_cat.ipynb 4
|
23 |
+
gr.Interface(fn=predict, inputs="image", outputs="label").launch(share=False)
|