PhDFlo commited on
Commit
dbe35a6
·
1 Parent(s): e4fb88b

change requirements

Browse files
Files changed (2) hide show
  1. app.ipynb +179 -0
  2. requirements.txt +1 -0
app.ipynb CHANGED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "143fb102",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 2,
16
+ "id": "d5bcdf28",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "#|export\n",
21
+ "from fastai.vision.all import *\n",
22
+ "import gradio as gr\n",
23
+ "\n",
24
+ "def is_cat(x): return x[0].isupper()"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 3,
30
+ "id": "6b2565d5",
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stderr",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "/home/florian/miniconda3/envs/env_transformers/lib/python3.11/site-packages/fastai/learner.py:455: UserWarning: load_learner` uses Python's insecure pickle module, which can execute malicious arbitrary code when loading. Only load files you trust.\n",
38
+ "If you only need to load model weights and optimizer state, use the safe `Learner.load` instead.\n",
39
+ " warn(\"load_learner` uses Python's insecure pickle module, which can execute malicious arbitrary code when loading. Only load files you trust.\\nIf you only need to load model weights and optimizer state, use the safe `Learner.load` instead.\")\n"
40
+ ]
41
+ }
42
+ ],
43
+ "source": [
44
+ "#|export\n",
45
+ "learn = load_learner('modelchampi.pkl')"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 4,
51
+ "id": "e24a470c",
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "#|export\n",
56
+ "categories = ('amanite','bolet', 'morille', 'truffe')\n",
57
+ "\n",
58
+ "def classify_image(img):\n",
59
+ " pred,idx,probs = learn.predict(img)\n",
60
+ " return dict(zip(categories, map(float,probs)))"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": 5,
66
+ "id": "ff8bb0b5",
67
+ "metadata": {},
68
+ "outputs": [
69
+ {
70
+ "data": {
71
+ "text/html": [
72
+ "\n",
73
+ "<style>\n",
74
+ " /* Turns off some styling */\n",
75
+ " progress {\n",
76
+ " /* gets rid of default border in Firefox and Opera. */\n",
77
+ " border: none;\n",
78
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
79
+ " background-size: auto;\n",
80
+ " }\n",
81
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
82
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
83
+ " }\n",
84
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
85
+ " background: #F44336;\n",
86
+ " }\n",
87
+ "</style>\n"
88
+ ],
89
+ "text/plain": [
90
+ "<IPython.core.display.HTML object>"
91
+ ]
92
+ },
93
+ "metadata": {},
94
+ "output_type": "display_data"
95
+ },
96
+ {
97
+ "data": {
98
+ "text/html": [],
99
+ "text/plain": [
100
+ "<IPython.core.display.HTML object>"
101
+ ]
102
+ },
103
+ "metadata": {},
104
+ "output_type": "display_data"
105
+ },
106
+ {
107
+ "data": {
108
+ "text/plain": [
109
+ "{'amanite': 0.9999909400939941,\n",
110
+ " 'bolet': 4.352936571194732e-07,\n",
111
+ " 'morille': 3.9385918171319645e-06,\n",
112
+ " 'truffe': 4.598049144988181e-06}"
113
+ ]
114
+ },
115
+ "execution_count": 5,
116
+ "metadata": {},
117
+ "output_type": "execute_result"
118
+ }
119
+ ],
120
+ "source": [
121
+ "classify_image('amanite.jpg')"
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "execution_count": 6,
127
+ "id": "a5b4b573",
128
+ "metadata": {},
129
+ "outputs": [
130
+ {
131
+ "name": "stdout",
132
+ "output_type": "stream",
133
+ "text": [
134
+ "* Running on local URL: http://127.0.0.1:7860\n",
135
+ "* To create a public link, set `share=True` in `launch()`.\n"
136
+ ]
137
+ },
138
+ {
139
+ "data": {
140
+ "text/plain": []
141
+ },
142
+ "execution_count": 6,
143
+ "metadata": {},
144
+ "output_type": "execute_result"
145
+ }
146
+ ],
147
+ "source": [
148
+ "#|export\n",
149
+ "image = gr.Image(height=192, width=192)\n",
150
+ "label = gr.Label()\n",
151
+ "examples = ['amanite.jpg', 'truffe.jpg']\n",
152
+ "\n",
153
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
154
+ "intf.launch(inline=False)"
155
+ ]
156
+ }
157
+ ],
158
+ "metadata": {
159
+ "kernelspec": {
160
+ "display_name": "env_transformers",
161
+ "language": "python",
162
+ "name": "python3"
163
+ },
164
+ "language_info": {
165
+ "codemirror_mode": {
166
+ "name": "ipython",
167
+ "version": 3
168
+ },
169
+ "file_extension": ".py",
170
+ "mimetype": "text/x-python",
171
+ "name": "python",
172
+ "nbconvert_exporter": "python",
173
+ "pygments_lexer": "ipython3",
174
+ "version": "3.11.11"
175
+ }
176
+ },
177
+ "nbformat": 4,
178
+ "nbformat_minor": 5
179
+ }
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  huggingface-hub
2
  fastai>=2.4
3
  fastcore>=1.3.27
 
4
  gradio
5
  numpy<2.0.0
6
  pandas<2.0.0
 
1
  huggingface-hub
2
  fastai>=2.4
3
  fastcore>=1.3.27
4
+ torch==2.6.0
5
  gradio
6
  numpy<2.0.0
7
  pandas<2.0.0