k-code commited on
Commit
778a0b7
·
1 Parent(s): dc5f6b6

add pil image

Browse files
Files changed (2) hide show
  1. app.py +2 -0
  2. is_cat.ipynb +143 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  from fastai.learner import load_learner
 
 
3
  def label_func(f): return f[0].isupper()
4
  learn = load_learner('export.pkl')
5
 
 
1
  import gradio as gr
2
  from fastai.learner import load_learner
3
+ from fastai.vision.all import PILImage
4
+
5
  def label_func(f): return f[0].isupper()
6
  learn = load_learner('export.pkl')
7
 
is_cat.ipynb CHANGED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 9,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "* Running on local URL: http://127.0.0.1:7865\n",
13
+ "* Running on public URL: https://b83dd3f618e0e3e8c5.gradio.live\n",
14
+ "\n",
15
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"
16
+ ]
17
+ },
18
+ {
19
+ "data": {
20
+ "text/html": [
21
+ "<div><iframe src=\"https://b83dd3f618e0e3e8c5.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
+ ],
23
+ "text/plain": [
24
+ "<IPython.core.display.HTML object>"
25
+ ]
26
+ },
27
+ "metadata": {},
28
+ "output_type": "display_data"
29
+ },
30
+ {
31
+ "data": {
32
+ "text/plain": []
33
+ },
34
+ "execution_count": 9,
35
+ "metadata": {},
36
+ "output_type": "execute_result"
37
+ },
38
+ {
39
+ "data": {
40
+ "text/html": [
41
+ "\n",
42
+ "<style>\n",
43
+ " /* Turns off some styling */\n",
44
+ " progress {\n",
45
+ " /* gets rid of default border in Firefox and Opera. */\n",
46
+ " border: none;\n",
47
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
48
+ " background-size: auto;\n",
49
+ " }\n",
50
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
51
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
52
+ " }\n",
53
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
54
+ " background: #F44336;\n",
55
+ " }\n",
56
+ "</style>\n"
57
+ ],
58
+ "text/plain": [
59
+ "<IPython.core.display.HTML object>"
60
+ ]
61
+ },
62
+ "metadata": {},
63
+ "output_type": "display_data"
64
+ },
65
+ {
66
+ "data": {
67
+ "text/html": [],
68
+ "text/plain": [
69
+ "<IPython.core.display.HTML object>"
70
+ ]
71
+ },
72
+ "metadata": {},
73
+ "output_type": "display_data"
74
+ }
75
+ ],
76
+ "source": [
77
+ "import gradio as gr\n",
78
+ "from fastai.learner import load_learner\n",
79
+ "from fastai.vision.all import PILImage\n",
80
+ "\n",
81
+ "def label_func(f): return f[0].isupper()\n",
82
+ "learn = load_learner('export.pkl')\n",
83
+ "\n",
84
+ "labels = learn.dls.vocab\n",
85
+ "\n",
86
+ "\n",
87
+ "def predict(img):\n",
88
+ " img = PILImage.create(img)\n",
89
+ " pred, pred_idx, probs = learn.predict(img)\n",
90
+ " return {labels[i]: float(probs[i]) for i in range(len(labels))}\n",
91
+ "\n",
92
+ "\n",
93
+ "title = \"Pet Breed Classifier\"\n",
94
+ "description = \"A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces.\"\n",
95
+ "article = \"<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>\"\n",
96
+ "examples = ['siamese.jpg']\n",
97
+ "interpretation = 'default'\n",
98
+ "enable_queue = True\n",
99
+ "\n",
100
+ "gr.Interface(\n",
101
+ " fn=predict,\n",
102
+ " inputs=gr.Image(type=\"filepath\"),\n",
103
+ " outputs=gr.Label(num_top_classes=3)\n",
104
+ ").launch(share=True)\n"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": null,
110
+ "metadata": {},
111
+ "outputs": [],
112
+ "source": []
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": null,
117
+ "metadata": {},
118
+ "outputs": [],
119
+ "source": []
120
+ }
121
+ ],
122
+ "metadata": {
123
+ "kernelspec": {
124
+ "display_name": "venv",
125
+ "language": "python",
126
+ "name": "python3"
127
+ },
128
+ "language_info": {
129
+ "codemirror_mode": {
130
+ "name": "ipython",
131
+ "version": 3
132
+ },
133
+ "file_extension": ".py",
134
+ "mimetype": "text/x-python",
135
+ "name": "python",
136
+ "nbconvert_exporter": "python",
137
+ "pygments_lexer": "ipython3",
138
+ "version": "3.12.2"
139
+ }
140
+ },
141
+ "nbformat": 4,
142
+ "nbformat_minor": 2
143
+ }