Spaces:
Runtime error
Runtime error
Amar Gill
commited on
Commit
·
8a82feb
1
Parent(s):
1437104
finish app
Browse files
app.py
CHANGED
@@ -1,9 +1,34 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
|
|
3 |
|
4 |
-
def greet(name):
|
5 |
-
return "Hello " + name + "!!"
|
6 |
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from skimage import PILImage
|
3 |
+
from fastai.vision.all import load_learner
|
4 |
|
5 |
+
learn = load_learner("model.pkl")
|
6 |
|
|
|
|
|
7 |
|
8 |
+
labels = learn.dls.vocab
|
9 |
|
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 |
+
|
17 |
+
title = "Pet Breed Classifier"
|
18 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
19 |
+
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
20 |
+
examples = ["siamese.PNG"]
|
21 |
+
interpretation = "default"
|
22 |
+
enable_queue = True
|
23 |
+
|
24 |
+
gr.Interface(
|
25 |
+
fn=predict,
|
26 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
27 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
28 |
+
title=title,
|
29 |
+
description=description,
|
30 |
+
article=article,
|
31 |
+
examples=examples,
|
32 |
+
interpretation=interpretation,
|
33 |
+
enable_queue=enable_queue,
|
34 |
+
).launch()
|