Spaces:
Sleeping
Sleeping
error handle
Browse files- .DS_Store +0 -0
- app.py +37 -30
- model.pkl → modeltest.pkl +2 -2
- requirements.txt +1 -3
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,33 +1,40 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 19 |
-
|
| 20 |
-
title = "Pet Breed Classifier"
|
| 21 |
-
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 22 |
-
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
| 23 |
examples = ['siamese.png']
|
| 24 |
|
| 25 |
-
gr.Interface(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def is_cat(x): return x[0].isupper()
|
| 5 |
+
|
| 6 |
+
learn = load_learner('modeltest.pkl')
|
| 7 |
+
|
| 8 |
+
categories = ('Dog', 'Cat')
|
| 9 |
+
|
| 10 |
+
def classify_image(img):
|
| 11 |
+
pred, idx, probs = learn.predict(img)
|
| 12 |
+
return dict(zip(categories, map(float, probs)))
|
| 13 |
+
|
| 14 |
+
image = gr.inputs.Image(shape=(192, 192))
|
| 15 |
+
label = gr.outputs.Label()
|
| 16 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
examples = ['siamese.png']
|
| 18 |
|
| 19 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 20 |
+
intf.launch(inline=False)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# labels = learn.dls.vocab
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# title = "Pet Breed Classifier"
|
| 28 |
+
# description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 29 |
+
# article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# gr.Interface(
|
| 33 |
+
# fn=predict,
|
| 34 |
+
# inputs=gr.Image(shape=(512, 512)), # Updated to newer Gradio syntax
|
| 35 |
+
# outputs=gr.Label(num_top_classes=3), # Updated to newer Gradio syntax
|
| 36 |
+
# title=title,
|
| 37 |
+
# description=description,
|
| 38 |
+
# article=article,
|
| 39 |
+
# examples=examples
|
| 40 |
+
# ).launch()
|
model.pkl → modeltest.pkl
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
|
| 3 |
+
size 47059947
|
requirements.txt
CHANGED
|
@@ -1,3 +1 @@
|
|
| 1 |
-
fastai
|
| 2 |
-
gradio
|
| 3 |
-
fasttransform
|
|
|
|
| 1 |
+
fastai
|
|
|
|
|
|