jhowardjr commited on
Commit
e9df4d3
·
1 Parent(s): 98b6bde

let's deploy to huggingface spaces

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .DS_Store
.ipynb_checkpoints/is_a_cat-checkpoint.ipynb ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "db4fccaf",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp test\n",
11
+ "\n",
12
+ "!pip install -Uqq fastai\n",
13
+ "!pip install -Uqq gradio"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "id": "7f067622",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "from fastai.vision.all import *\n",
24
+ "\n",
25
+ "def is_cat(x): return x[0].isupper() "
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 3,
31
+ "id": "2a2f5376",
32
+ "metadata": {},
33
+ "outputs": [],
34
+ "source": [
35
+ "learn = load_learner('model.pkl')"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 4,
41
+ "id": "2ee57395",
42
+ "metadata": {},
43
+ "outputs": [],
44
+ "source": [
45
+ "labels = learn.dls.vocab\n",
46
+ "def predict(img):\n",
47
+ " img = PILImage.create(img)\n",
48
+ " pred,pred_idx,probs = learn.predict(img)\n",
49
+ " return {labels[i]: float(probs[i]) for i in range(len(labels))}"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 5,
55
+ "id": "7e0abb03",
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "name": "stdout",
60
+ "output_type": "stream",
61
+ "text": [
62
+ "Running on local URL: http://127.0.0.1:7860\n",
63
+ "\n",
64
+ "To create a public link, set `share=True` in `launch()`.\n"
65
+ ]
66
+ },
67
+ {
68
+ "data": {
69
+ "text/html": [
70
+ "<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>"
71
+ ],
72
+ "text/plain": [
73
+ "<IPython.core.display.HTML object>"
74
+ ]
75
+ },
76
+ "metadata": {},
77
+ "output_type": "display_data"
78
+ },
79
+ {
80
+ "data": {
81
+ "text/plain": []
82
+ },
83
+ "execution_count": 5,
84
+ "metadata": {},
85
+ "output_type": "execute_result"
86
+ }
87
+ ],
88
+ "source": [
89
+ "#|export\n",
90
+ "import gradio as gr\n",
91
+ "\n",
92
+ "gr.Interface(fn=predict, inputs=\"image\", outputs=\"label\").launch(share=False)"
93
+ ]
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "execution_count": 6,
98
+ "id": "22dc9b3a",
99
+ "metadata": {},
100
+ "outputs": [
101
+ {
102
+ "name": "stdout",
103
+ "output_type": "stream",
104
+ "text": [
105
+ "Export successful\n"
106
+ ]
107
+ },
108
+ {
109
+ "name": "stderr",
110
+ "output_type": "stream",
111
+ "text": [
112
+ "/Users/admin/mambaforge/lib/python3.10/site-packages/nbdev/export.py:54: UserWarning: Notebook 'is_a_cat.ipynb' uses `#|export` without `#|default_exp` cell.\n",
113
+ "Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n",
114
+ "See https://nbdev.fast.ai/getting_started.html for more information.\n",
115
+ " warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n"
116
+ ]
117
+ }
118
+ ],
119
+ "source": [
120
+ "import nbdev\n",
121
+ "nbdev.export.nb_export('is_a_cat.ipynb', 'app')\n",
122
+ "print('Export successful')"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": null,
128
+ "id": "baca5791",
129
+ "metadata": {},
130
+ "outputs": [],
131
+ "source": []
132
+ }
133
+ ],
134
+ "metadata": {
135
+ "kernelspec": {
136
+ "display_name": "Python 3 (ipykernel)",
137
+ "language": "python",
138
+ "name": "python3"
139
+ },
140
+ "language_info": {
141
+ "codemirror_mode": {
142
+ "name": "ipython",
143
+ "version": 3
144
+ },
145
+ "file_extension": ".py",
146
+ "mimetype": "text/x-python",
147
+ "name": "python",
148
+ "nbconvert_exporter": "python",
149
+ "pygments_lexer": "ipython3",
150
+ "version": "3.10.12"
151
+ }
152
+ },
153
+ "nbformat": 4,
154
+ "nbformat_minor": 5
155
+ }
is_a_cat.ipynb ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "db4fccaf",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app\n",
11
+ "\n",
12
+ "!pip install -Uqq fastai\n",
13
+ "!pip install -Uqq gradio"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "id": "7f067622",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "#|export\n",
24
+ "\n",
25
+ "from fastai.vision.all import *\n",
26
+ "import gradio as gr\n",
27
+ "\n",
28
+ "def is_cat(x): return x[0].isupper() "
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 3,
34
+ "id": "2a2f5376",
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "#|export\n",
39
+ "\n",
40
+ "learn = load_learner('model.pkl')"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": 4,
46
+ "id": "2ee57395",
47
+ "metadata": {},
48
+ "outputs": [],
49
+ "source": [
50
+ "#|export\n",
51
+ "\n",
52
+ "labels = learn.dls.vocab\n",
53
+ "def predict(img):\n",
54
+ " img = PILImage.create(img)\n",
55
+ " pred,pred_idx,probs = learn.predict(img)\n",
56
+ " return {labels[i]: float(probs[i]) for i in range(len(labels))}"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 5,
62
+ "id": "7e0abb03",
63
+ "metadata": {},
64
+ "outputs": [
65
+ {
66
+ "name": "stdout",
67
+ "output_type": "stream",
68
+ "text": [
69
+ "Running on local URL: http://127.0.0.1:7860\n",
70
+ "\n",
71
+ "To create a public link, set `share=True` in `launch()`.\n"
72
+ ]
73
+ },
74
+ {
75
+ "data": {
76
+ "text/html": [
77
+ "<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>"
78
+ ],
79
+ "text/plain": [
80
+ "<IPython.core.display.HTML object>"
81
+ ]
82
+ },
83
+ "metadata": {},
84
+ "output_type": "display_data"
85
+ },
86
+ {
87
+ "data": {
88
+ "text/plain": []
89
+ },
90
+ "execution_count": 5,
91
+ "metadata": {},
92
+ "output_type": "execute_result"
93
+ }
94
+ ],
95
+ "source": [
96
+ "#|export\n",
97
+ "\n",
98
+ "gr.Interface(fn=predict, inputs=\"image\", outputs=\"label\").launch(share=False)"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 1,
104
+ "id": "22dc9b3a",
105
+ "metadata": {},
106
+ "outputs": [
107
+ {
108
+ "name": "stdout",
109
+ "output_type": "stream",
110
+ "text": [
111
+ "Export successful\n"
112
+ ]
113
+ }
114
+ ],
115
+ "source": [
116
+ "import nbdev\n",
117
+ "nbdev.export.nb_export('is_a_cat.ipynb', './')\n",
118
+ "print('Export successful')"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": null,
124
+ "id": "baca5791",
125
+ "metadata": {},
126
+ "outputs": [],
127
+ "source": []
128
+ }
129
+ ],
130
+ "metadata": {
131
+ "kernelspec": {
132
+ "display_name": "Python 3 (ipykernel)",
133
+ "language": "python",
134
+ "name": "python3"
135
+ },
136
+ "language_info": {
137
+ "codemirror_mode": {
138
+ "name": "ipython",
139
+ "version": 3
140
+ },
141
+ "file_extension": ".py",
142
+ "mimetype": "text/x-python",
143
+ "name": "python",
144
+ "nbconvert_exporter": "python",
145
+ "pygments_lexer": "ipython3",
146
+ "version": "3.10.12"
147
+ }
148
+ },
149
+ "nbformat": 4,
150
+ "nbformat_minor": 5
151
+ }
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:312c19ad0c62723d0cbff868982180b9a8e71c66c9c27f03bcddc6489d9181db
3
+ size 47064766