Spaces:
Build error
Build error
Initial commit
Browse files- README.md +3 -3
- app.py +32 -0
- boerboel.jpg +0 -0
- cat_dog_model.pkl +3 -0
- demo.ipynb +124 -0
- german_shepherd.jpg +0 -0
- requirements.txt +2 -0
- siamese.jpg +0 -0
- sphynx.jpg +0 -0
README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
-
title: Cats
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.9
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Cats N Dogs
|
| 3 |
+
emoji: 🐱
|
| 4 |
+
colorFrom: yellow
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 3.9
|
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import skimage
|
| 4 |
+
|
| 5 |
+
# Function needed to set labels
|
| 6 |
+
def is_cat(filename):
|
| 7 |
+
return filename.name[0].isupper()
|
| 8 |
+
|
| 9 |
+
learn = load_learner('cat_dog_model.pkl')
|
| 10 |
+
labels = learn.dls.vocab
|
| 11 |
+
|
| 12 |
+
def predict(img):
|
| 13 |
+
img = PILImage.create(img)
|
| 14 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 15 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
title = "Cat/Dog Classifier"
|
| 19 |
+
description = "Basic Cat/Dog classifier trained on the Oxford Pets dataset with fastai. Testing out Gradio on HF Spaces."
|
| 20 |
+
examples = ['siamese.jpg', 'boerboel.jpg', 'german_shepherd.jpg', 'sphynx.jpg']
|
| 21 |
+
enable_queue=True
|
| 22 |
+
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs=gr.Image(shape=(512,512)),
|
| 26 |
+
outputs=gr.Label(num_top_classes=3),
|
| 27 |
+
title=title,
|
| 28 |
+
description=description,
|
| 29 |
+
examples=examples,
|
| 30 |
+
).launch(enable_queue=enable_queue)
|
| 31 |
+
|
| 32 |
+
|
boerboel.jpg
ADDED
|
cat_dog_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8727159e573fed157946386cb511af61e01b5040e089a114fa8cc06bc800723e
|
| 3 |
+
size 47081707
|
demo.ipynb
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
+
"id": "71299281",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"from fastai.vision.all import *\n",
|
| 11 |
+
"import gradio as gr\n",
|
| 12 |
+
"import skimage"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"execution_count": 3,
|
| 18 |
+
"id": "7d256402",
|
| 19 |
+
"metadata": {},
|
| 20 |
+
"outputs": [],
|
| 21 |
+
"source": [
|
| 22 |
+
"# Function needed to set labels\n",
|
| 23 |
+
"def is_cat(filename):\n",
|
| 24 |
+
" return filename.name[0].isupper() "
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "code",
|
| 29 |
+
"execution_count": 4,
|
| 30 |
+
"id": "a350f960",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [],
|
| 33 |
+
"source": [
|
| 34 |
+
"learn = load_learner('cat_dog_model.pkl')\n",
|
| 35 |
+
"labels = learn.dls.vocab\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"def predict(img):\n",
|
| 38 |
+
" img = PILImage.create(img)\n",
|
| 39 |
+
" pred, pred_idx, probs = learn.predict(img)\n",
|
| 40 |
+
" return {labels[i]: float(probs[i]) for i in range(len(labels))}"
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"cell_type": "code",
|
| 45 |
+
"execution_count": 5,
|
| 46 |
+
"id": "8703a184",
|
| 47 |
+
"metadata": {},
|
| 48 |
+
"outputs": [
|
| 49 |
+
{
|
| 50 |
+
"name": "stdout",
|
| 51 |
+
"output_type": "stream",
|
| 52 |
+
"text": [
|
| 53 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"data": {
|
| 60 |
+
"text/html": [
|
| 61 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 62 |
+
],
|
| 63 |
+
"text/plain": [
|
| 64 |
+
"<IPython.core.display.HTML object>"
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
"metadata": {},
|
| 68 |
+
"output_type": "display_data"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"data": {
|
| 72 |
+
"text/plain": [
|
| 73 |
+
"(<gradio.routes.App at 0x7f5b0f748d90>, 'http://127.0.0.1:7860/', None)"
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
"execution_count": 5,
|
| 77 |
+
"metadata": {},
|
| 78 |
+
"output_type": "execute_result"
|
| 79 |
+
}
|
| 80 |
+
],
|
| 81 |
+
"source": [
|
| 82 |
+
"title = \"Cat/Dog Classifier\"\n",
|
| 83 |
+
"description = \"Basic Cat/Dog classifier trained on the Oxford Pets dataset with fastai. Testing out Gradio on HF Spaces.\"\n",
|
| 84 |
+
"examples = ['siamese.jpg', 'boerboel.jpg', 'german_shepherd.jpg', 'sphynx.jpg']\n",
|
| 85 |
+
"enable_queue=True\n",
|
| 86 |
+
"\n",
|
| 87 |
+
"gr.Interface(\n",
|
| 88 |
+
" fn=predict, \n",
|
| 89 |
+
" inputs=gr.Image(shape=(512,512)),\n",
|
| 90 |
+
" outputs=gr.Label(num_top_classes=3),\n",
|
| 91 |
+
" title=title,\n",
|
| 92 |
+
" description=description,\n",
|
| 93 |
+
" examples=examples,\n",
|
| 94 |
+
").launch(enable_queue=enable_queue)"
|
| 95 |
+
]
|
| 96 |
+
}
|
| 97 |
+
],
|
| 98 |
+
"metadata": {
|
| 99 |
+
"kernelspec": {
|
| 100 |
+
"display_name": "Python 3.10.6 ('base')",
|
| 101 |
+
"language": "python",
|
| 102 |
+
"name": "python3"
|
| 103 |
+
},
|
| 104 |
+
"language_info": {
|
| 105 |
+
"codemirror_mode": {
|
| 106 |
+
"name": "ipython",
|
| 107 |
+
"version": 3
|
| 108 |
+
},
|
| 109 |
+
"file_extension": ".py",
|
| 110 |
+
"mimetype": "text/x-python",
|
| 111 |
+
"name": "python",
|
| 112 |
+
"nbconvert_exporter": "python",
|
| 113 |
+
"pygments_lexer": "ipython3",
|
| 114 |
+
"version": "3.10.6"
|
| 115 |
+
},
|
| 116 |
+
"vscode": {
|
| 117 |
+
"interpreter": {
|
| 118 |
+
"hash": "ed0e91aaffcefde6eb9bcd4f55fe7652d77471dc031ce772257aa5eb4a54e8f2"
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
},
|
| 122 |
+
"nbformat": 4,
|
| 123 |
+
"nbformat_minor": 5
|
| 124 |
+
}
|
german_shepherd.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
scikit-image
|
siamese.jpg
ADDED
|
sphynx.jpg
ADDED
|