Spaces:
Runtime error
Runtime error
app + requirements
Browse files- app.py +24 -4
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../01.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learner', 'labels', 'image', 'predict']
|
5 |
+
|
6 |
+
# %% ../01.ipynb 3
|
7 |
+
from fastai.vision.all import *
|
8 |
+
|
9 |
+
# %% ../01.ipynb 4
|
10 |
+
learner = load_learner('model.pkl')
|
11 |
+
|
12 |
+
# %% ../01.ipynb 5
|
13 |
+
labels = learner.dls.vocab
|
14 |
+
def predict(img):
|
15 |
+
img = PILImage.create(img)
|
16 |
+
pred,pred_idx,probs = learner.predict(img)
|
17 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
18 |
+
|
19 |
+
# %% ../01.ipynb 7
|
20 |
import gradio as gr
|
21 |
|
22 |
+
# %% ../01.ipynb 8
|
23 |
+
image = gr.inputs.Image(shape=(512, 512))
|
24 |
+
labels = gr.outputs.Label(num_top_classes=3)
|
25 |
|
26 |
+
gr.Interface(fn=predict, inputs=image, outputs=labels)
|
27 |
+
gr.launch(inline=False)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai==2.7.10
|
2 |
+
scikit-image
|