imtharun commited on
Commit
db3757f
·
1 Parent(s): 53e6ff5

Feat: added gradio and git lfs to track

Browse files
Files changed (6) hide show
  1. app.ipynb +145 -0
  2. app.py +28 -4
  3. beagle.jpg +0 -0
  4. cat.jpg +0 -0
  5. dog.jpg +0 -0
  6. model.pkl +3 -0
app.ipynb ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 12,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "#|default_exp app"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 3,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "#|export\n",
19
+ "from fastai.vision.all import *\n",
20
+ "import gradio as gr"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 2,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "#|export\n",
30
+ "\n",
31
+ "def is_cat(x):\n",
32
+ " return x[0].isupper()"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 4,
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "source": [
41
+ "#|export\n",
42
+ "\n",
43
+ "learn = load_learner('model.pkl')"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 5,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "#|export\n",
53
+ "\n",
54
+ "categories = ('Dog', 'Cat')\n",
55
+ "\n",
56
+ "def classify_image(img):\n",
57
+ " pred, idx, probs = learn.predict(img)\n",
58
+ " return dict(zip(categories, map(float, probs)))"
59
+ ]
60
+ },
61
+ {
62
+ "cell_type": "code",
63
+ "execution_count": 6,
64
+ "metadata": {},
65
+ "outputs": [
66
+ {
67
+ "name": "stderr",
68
+ "output_type": "stream",
69
+ "text": [
70
+ "/tmp/ipykernel_232403/3480190996.py:3: GradioDeprecationWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
71
+ " image = gr.inputs.Image(shape=(192, 192))\n",
72
+ "/tmp/ipykernel_232403/3480190996.py:3: GradioDeprecationWarning: `optional` parameter is deprecated, and it has no effect\n",
73
+ " image = gr.inputs.Image(shape=(192, 192))\n",
74
+ "/tmp/ipykernel_232403/3480190996.py:4: GradioDeprecationWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
75
+ " label = gr.outputs.Label()\n",
76
+ "/tmp/ipykernel_232403/3480190996.py:4: GradioUnusedKwargWarning: You have unused kwarg parameters in Label, please remove them: {'type': 'auto'}\n",
77
+ " label = gr.outputs.Label()\n"
78
+ ]
79
+ },
80
+ {
81
+ "name": "stdout",
82
+ "output_type": "stream",
83
+ "text": [
84
+ "Running on local URL: http://127.0.0.1:7860\n",
85
+ "IMPORTANT: You are using gradio version 3.43.0, however version 4.29.0 is available, please upgrade.\n",
86
+ "--------\n",
87
+ "Running on public URL: https://1ff37f198fe37a32c2.gradio.live\n",
88
+ "\n",
89
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
90
+ ]
91
+ },
92
+ {
93
+ "data": {
94
+ "text/plain": []
95
+ },
96
+ "execution_count": 6,
97
+ "metadata": {},
98
+ "output_type": "execute_result"
99
+ }
100
+ ],
101
+ "source": [
102
+ "#|export\n",
103
+ "\n",
104
+ "image = gr.inputs.Image(shape=(192, 192))\n",
105
+ "label = gr.outputs.Label()\n",
106
+ "examples = ['dog.jpg', 'cat.jpg', 'beagle.jpg']\n",
107
+ "\n",
108
+ "interface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
109
+ "interface.launch(inline=False, share=True)"
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "execution_count": 13,
115
+ "metadata": {},
116
+ "outputs": [],
117
+ "source": [
118
+ "import nbdev\n",
119
+ "\n",
120
+ "nbdev.export.nb_export('app.ipynb')"
121
+ ]
122
+ }
123
+ ],
124
+ "metadata": {
125
+ "kernelspec": {
126
+ "display_name": "Python 3",
127
+ "language": "python",
128
+ "name": "python3"
129
+ },
130
+ "language_info": {
131
+ "codemirror_mode": {
132
+ "name": "ipython",
133
+ "version": 3
134
+ },
135
+ "file_extension": ".py",
136
+ "mimetype": "text/x-python",
137
+ "name": "python",
138
+ "nbconvert_exporter": "python",
139
+ "pygments_lexer": "ipython3",
140
+ "version": "3.10.12"
141
+ }
142
+ },
143
+ "nbformat": 4,
144
+ "nbformat_minor": 2
145
+ }
app.py CHANGED
@@ -1,6 +1,30 @@
1
- import gradio as gradio
2
 
3
- def greet(name):
4
- return f'Hello {name}'
5
 
6
- gradio.Interface(fn=greet, inputs="text", outputs="text").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
2
 
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interface', 'is_cat', 'classify_image']
5
 
6
+ # %% ../app.ipynb 1
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+
10
+ # %% ../app.ipynb 2
11
+ def is_cat(x):
12
+ return x[0].isupper()
13
+
14
+ # %% ../app.ipynb 3
15
+ learn = load_learner('model.pkl')
16
+
17
+ # %% ../app.ipynb 4
18
+ categories = ('Dog', 'Cat')
19
+
20
+ def classify_image(img):
21
+ pred, idx, probs = learn.predict(img)
22
+ return dict(zip(categories, map(float, probs)))
23
+
24
+ # %% ../app.ipynb 5
25
+ image = gr.inputs.Image(shape=(192, 192))
26
+ label = gr.outputs.Label()
27
+ examples = ['dog.jpg', 'cat.jpg', 'beagle.jpg']
28
+
29
+ interface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
30
+ interface.launch(inline=False, share=True)
beagle.jpg ADDED
cat.jpg ADDED
dog.jpg ADDED
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
3
+ size 47059947