Spaces:
Runtime error
Runtime error
Add predict func and inference chain
Browse files
app.py
CHANGED
|
@@ -1,7 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from fastai.learner import load_learner
|
| 4 |
+
from fastai.vision.all import PILImage
|
| 5 |
|
| 6 |
+
|
| 7 |
+
learn = load_learner('model/export.pkl')
|
| 8 |
+
|
| 9 |
+
labels = learn.dls.vocab
|
| 10 |
+
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = PILImage.create(img)
|
| 13 |
+
pred,pred_idx,probs = learn.predict(img)
|
| 14 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(fn=predict, inputs=gr.Image(shape=(512, 512)), outputs=gr.Label(num_top_classes=3)).launch(share=True)
|
| 17 |
iface.launch()
|