Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
@@ -2,18 +2,17 @@ import gradio as gr
|
|
2 |
from fastai.vision.all import *
|
3 |
import json
|
4 |
|
5 |
-
def is_cat(x): return x[0].isupper()
|
6 |
-
|
7 |
-
|
8 |
learn = load_learner('model.pkl')
|
9 |
|
10 |
with open('categories.json', 'r') as f:
|
11 |
-
|
|
|
|
|
12 |
|
13 |
def predict(img):
|
14 |
img = PILImage.create(img)
|
15 |
-
|
16 |
-
return {labels[
|
17 |
|
18 |
|
19 |
title = "Predict flower species"
|
|
|
2 |
from fastai.vision.all import *
|
3 |
import json
|
4 |
|
|
|
|
|
|
|
5 |
learn = load_learner('model.pkl')
|
6 |
|
7 |
with open('categories.json', 'r') as f:
|
8 |
+
categories = json.load(f)
|
9 |
+
|
10 |
+
labels = learn.dls.vocab
|
11 |
|
12 |
def predict(img):
|
13 |
img = PILImage.create(img)
|
14 |
+
_, _, probs = learn.predict(img)
|
15 |
+
return {f"{categories[labels[i]]} ({labels[i]})": float(probs[i]) for i in range(len(labels))}
|
16 |
|
17 |
|
18 |
title = "Predict flower species"
|