Spaces:
Runtime error
Runtime error
yvoievid
commited on
Commit
·
b804560
1
Parent(s):
da95c85
change app.py to run on Hugging Face
Browse files
app.py
CHANGED
@@ -4,15 +4,26 @@ from fastai.vision.all import *
|
|
4 |
|
5 |
learn = load_learner('model.pkl')
|
6 |
|
|
|
7 |
labels = learn.dls.vocab
|
8 |
def predict(img):
|
9 |
img = PILImage.create(img)
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
learn = load_learner('model.pkl')
|
6 |
|
7 |
+
|
8 |
labels = learn.dls.vocab
|
9 |
def predict(img):
|
10 |
img = PILImage.create(img)
|
11 |
+
pred,pred_idx,probs = learn.predict(img)
|
12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
13 |
|
14 |
+
title = "Horde or Aliance Classifier"
|
15 |
+
description = "Horde or Aliance Classifier created in Hugging Face Spaces"
|
16 |
+
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
17 |
+
examples = ['horde.jpeg', 'alliance.jpeg']
|
18 |
+
interpretation='default'
|
19 |
+
enable_queue=True
|
20 |
|
21 |
+
gr.Interface(fn=predict,
|
22 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
23 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
24 |
+
title=title,
|
25 |
+
description=description,
|
26 |
+
article=article,
|
27 |
+
examples=examples,
|
28 |
+
interpretation=interpretation,
|
29 |
+
enable_queue=enable_queue).launch()
|