Spaces:
Runtime error
Runtime error
Commit
·
3dc35ba
1
Parent(s):
851a023
Adjustment 3
Browse files- .ipynb_checkpoints/Untitled-checkpoint.ipynb +6 -0
- .ipynb_checkpoints/app-checkpoint.py +20 -0
- Untitled.ipynb +72 -0
- app.py +1 -2
- model.pkl +2 -2
.ipynb_checkpoints/Untitled-checkpoint.ipynb
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [],
|
| 3 |
+
"metadata": {},
|
| 4 |
+
"nbformat": 4,
|
| 5 |
+
"nbformat_minor": 5
|
| 6 |
+
}
|
.ipynb_checkpoints/app-checkpoint.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import fastai
|
| 2 |
+
from fastai.vision import load_learner
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def is_cat(x):
|
| 6 |
+
return x[0].isupper()
|
| 7 |
+
|
| 8 |
+
learn = load_learner('model.pkl')
|
| 9 |
+
|
| 10 |
+
categories = ('Dog', 'Cat')
|
| 11 |
+
|
| 12 |
+
def classify_image(img):
|
| 13 |
+
pred,idx,probs = learn.predict(img)
|
| 14 |
+
return dict(zip(categories), map(float,probs))
|
| 15 |
+
|
| 16 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 17 |
+
label = gr.outputs.Label()
|
| 18 |
+
|
| 19 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
|
| 20 |
+
intf.launch(inline=False)
|
Untitled.ipynb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 9,
|
| 6 |
+
"id": "a9c14507-a23e-4bd8-990e-d45a7460339d",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"ename": "NameError",
|
| 11 |
+
"evalue": "name 'MNIST_PATH' is not defined",
|
| 12 |
+
"output_type": "error",
|
| 13 |
+
"traceback": [
|
| 14 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 15 |
+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
| 16 |
+
"Cell \u001b[1;32mIn[9], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfastai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mall\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m----> 2\u001b[0m path \u001b[38;5;241m=\u001b[39m untar_data(MNIST_PATH)\n\u001b[0;32m 3\u001b[0m data \u001b[38;5;241m=\u001b[39m image_data_from_folder(path)\n\u001b[0;32m 4\u001b[0m learn \u001b[38;5;241m=\u001b[39m cnn_learner(data, models\u001b[38;5;241m.\u001b[39mresnet18, metrics\u001b[38;5;241m=\u001b[39maccuracy)\n",
|
| 17 |
+
"\u001b[1;31mNameError\u001b[0m: name 'MNIST_PATH' is not defined"
|
| 18 |
+
]
|
| 19 |
+
}
|
| 20 |
+
],
|
| 21 |
+
"source": [
|
| 22 |
+
"from fastai.vision.all import *\n",
|
| 23 |
+
"import gradio as gr\n",
|
| 24 |
+
"def is_cat(x):\n",
|
| 25 |
+
" return x[0].isupper()\n",
|
| 26 |
+
"\n",
|
| 27 |
+
"learn = load_learner('model.pkl')\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"categories = ('Dog', 'Cat')\n",
|
| 30 |
+
"\n",
|
| 31 |
+
"def classify_image(img):\n",
|
| 32 |
+
" pred,idx,probs = learn.predict(img)\n",
|
| 33 |
+
" return dict(zip(categories), map(float,probs))\n",
|
| 34 |
+
"\n",
|
| 35 |
+
"image = gr.inputs.Image(shape=(192,192))\n",
|
| 36 |
+
"label = gr.outputs.Label()\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n",
|
| 39 |
+
"intf.launch(inline=False)"
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"cell_type": "code",
|
| 44 |
+
"execution_count": null,
|
| 45 |
+
"id": "c353f37d-7f82-4179-bf86-7cfa96d3d0b0",
|
| 46 |
+
"metadata": {},
|
| 47 |
+
"outputs": [],
|
| 48 |
+
"source": []
|
| 49 |
+
}
|
| 50 |
+
],
|
| 51 |
+
"metadata": {
|
| 52 |
+
"kernelspec": {
|
| 53 |
+
"display_name": "Python 3 (ipykernel)",
|
| 54 |
+
"language": "python",
|
| 55 |
+
"name": "python3"
|
| 56 |
+
},
|
| 57 |
+
"language_info": {
|
| 58 |
+
"codemirror_mode": {
|
| 59 |
+
"name": "ipython",
|
| 60 |
+
"version": 3
|
| 61 |
+
},
|
| 62 |
+
"file_extension": ".py",
|
| 63 |
+
"mimetype": "text/x-python",
|
| 64 |
+
"name": "python",
|
| 65 |
+
"nbconvert_exporter": "python",
|
| 66 |
+
"pygments_lexer": "ipython3",
|
| 67 |
+
"version": "3.12.3"
|
| 68 |
+
}
|
| 69 |
+
},
|
| 70 |
+
"nbformat": 4,
|
| 71 |
+
"nbformat_minor": 5
|
| 72 |
+
}
|
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
from fastai.vision import load_learner
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
def is_cat(x):
|
|
|
|
| 1 |
+
from fastai.vision import *
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
def is_cat(x):
|
model.pkl
CHANGED
|
@@ -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:f60f78e8c4a2a58e05a5503956ac1f9e66eeb24818025efb9808031a61221011
|
| 3 |
+
size 47062270
|