Spaces:
Sleeping
Sleeping
Ulf Hammerschmied
commited on
Commit
·
05fc356
1
Parent(s):
77f43a9
export.pkl -> model.pkl
Browse files
app.py
CHANGED
@@ -1,37 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
from fastai.vision.core import PILImage
|
4 |
from fastai.learner import load_learner
|
5 |
-
import pathlib
|
6 |
|
7 |
-
value = pathlib.Path().resolve()
|
8 |
-
value2 = os.listdir()
|
9 |
|
|
|
|
|
10 |
|
11 |
-
def greet(name):
|
12 |
-
return "Hello " + name + "!"
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# title = "Bear Classifier"
|
28 |
-
# description = ("A bear classifier trained on black/grizzly/teddy bear images downloaded from internet with fastai. "
|
29 |
-
# "Created as a demo for Gradio and HuggingFace Spaces.")
|
30 |
-
# examples = ['black.jpg', 'grizzly.jpg', 'teddy.jpg']
|
31 |
-
# grif = gr.Interface(fn=predict,
|
32 |
-
# inputs=gr.inputs.Image(shape=(512, 512)),
|
33 |
-
# outputs=gr.outputs.Label(num_top_classes=3),
|
34 |
-
# title=title,
|
35 |
-
# description=description,
|
36 |
-
# examples=examples)
|
37 |
-
# grif.launch(share=True)
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from fastai.vision.core import PILImage
|
3 |
from fastai.learner import load_learner
|
|
|
4 |
|
|
|
|
|
5 |
|
6 |
+
learn = load_learner('model.pkl')
|
7 |
+
labels = learn.dls.vocab
|
8 |
|
|
|
|
|
9 |
|
10 |
+
def predict(img):
|
11 |
+
img = PILImage.create(img)
|
12 |
+
pred, pred_idx, probs = learn.predict(img)
|
13 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
14 |
|
15 |
+
|
16 |
+
title = "Bear Classifier"
|
17 |
+
description = ("A bear classifier trained on black/grizzly/teddy bear images downloaded from internet with fastai. "
|
18 |
+
"Created as a demo for Gradio and HuggingFace Spaces.")
|
19 |
+
examples = ['black.jpg', 'grizzly.jpg', 'teddy.jpg']
|
20 |
+
grif = gr.Interface(fn=predict,
|
21 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
22 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
23 |
+
title=title,
|
24 |
+
description=description,
|
25 |
+
examples=examples)
|
26 |
+
grif.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|