Spaces:
Runtime error
Runtime error
irakli-ff
commited on
Commit
•
40dbd48
1
Parent(s):
8d2b508
first_deployment
Browse files- .gitignore +8 -0
- .ipynb_checkpoints/Runpod-checkpoint.ipynb +6 -0
- .ipynb_checkpoints/app-checkpoint.ipynb +159 -0
- .ipynb_checkpoints/load_data-checkpoint.ipynb +92 -0
- .ipynb_checkpoints/pre-process-checkpoint.ipynb +6 -0
- Runpod.ipynb +116 -0
- app.ipynb +164 -0
- app.py +34 -0
- data_loader.ipynb +0 -0
- load_data.ipynb +0 -0
- model.pkl +3 -0
.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
**/cache/
|
2 |
+
*.tmp
|
3 |
+
pre-processed.zip
|
4 |
+
pre-process.ipynb
|
5 |
+
model_pics/
|
6 |
+
pre-processed/
|
7 |
+
Runpod.ipynb/
|
8 |
+
stars.csv
|
.ipynb_checkpoints/Runpod-checkpoint.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
.ipynb_checkpoints/app-checkpoint.ipynb
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"#|default_exp app2"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": 2,
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"#|export\n",
|
19 |
+
"from fastai.vision.all import *\n",
|
20 |
+
"import gradio as gr\n",
|
21 |
+
"import io\n",
|
22 |
+
"from PIL import Image\n",
|
23 |
+
"\n",
|
24 |
+
"def pet_class(x): return x"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 3,
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [],
|
32 |
+
"source": [
|
33 |
+
"#|export\n",
|
34 |
+
"learn = load_learner('model.pkl')"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 4,
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"#|export\n",
|
44 |
+
"#categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')\n",
|
45 |
+
"\n",
|
46 |
+
"def classify_image(img):\n",
|
47 |
+
" pred_class, pred_idx, probs = learn.predict(img)\n",
|
48 |
+
" return dict(zip(categories, map(float,probs)))"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": 6,
|
54 |
+
"metadata": {},
|
55 |
+
"outputs": [
|
56 |
+
{
|
57 |
+
"name": "stdout",
|
58 |
+
"output_type": "stream",
|
59 |
+
"text": [
|
60 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
61 |
+
"\n",
|
62 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"data": {
|
67 |
+
"text/plain": []
|
68 |
+
},
|
69 |
+
"execution_count": 6,
|
70 |
+
"metadata": {},
|
71 |
+
"output_type": "execute_result"
|
72 |
+
}
|
73 |
+
],
|
74 |
+
"source": [
|
75 |
+
"#|export\n",
|
76 |
+
"image = gr.components.Image(shape=(192,192))\n",
|
77 |
+
"label = gr.components.Label()\n",
|
78 |
+
"#examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']\n",
|
79 |
+
"\n",
|
80 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n",
|
81 |
+
"intf.launch(inline=False)"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 5,
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [
|
89 |
+
{
|
90 |
+
"ename": "FileNotFoundError",
|
91 |
+
"evalue": "[Errno 2] No such file or directory: 'basketball.png'",
|
92 |
+
"output_type": "error",
|
93 |
+
"traceback": [
|
94 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
95 |
+
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
96 |
+
"Cell \u001b[0;32mIn[5], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m label \u001b[38;5;241m=\u001b[39m gr\u001b[38;5;241m.\u001b[39mcomponents\u001b[38;5;241m.\u001b[39mLabel()\n\u001b[1;32m 4\u001b[0m examples \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbasketball.png\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgolf_ball.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrugby_ball.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msoccer_ball.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m----> 6\u001b[0m intf \u001b[38;5;241m=\u001b[39m \u001b[43mgr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mInterface\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclassify_image\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mimage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m intf\u001b[38;5;241m.\u001b[39mlaunch(inline\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
|
97 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/interface.py:475\u001b[0m, in \u001b[0;36mInterface.__init__\u001b[0;34m(self, fn, inputs, outputs, examples, cache_examples, examples_per_page, live, interpretation, num_shap, title, description, article, thumbnail, theme, css, allow_flagging, flagging_options, flagging_dir, flagging_callback, analytics_enabled, batch, max_batch_size, _api_mode, **kwargs)\u001b[0m\n\u001b[1;32m 467\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_interpretation_events(\n\u001b[1;32m 468\u001b[0m interpretation_btn,\n\u001b[1;32m 469\u001b[0m interpretation_set,\n\u001b[1;32m 470\u001b[0m input_component_column,\n\u001b[1;32m 471\u001b[0m interpret_component_column,\n\u001b[1;32m 472\u001b[0m )\n\u001b[1;32m 474\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_flagging_events(flag_btns, clear_btn)\n\u001b[0;32m--> 475\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender_examples\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 476\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrender_article()\n\u001b[1;32m 478\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_config_file()\n",
|
98 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/interface.py:791\u001b[0m, in \u001b[0;36mInterface.render_examples\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 785\u001b[0m non_state_inputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 786\u001b[0m c \u001b[38;5;28;01mfor\u001b[39;00m c \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_components \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(c, State)\n\u001b[1;32m 787\u001b[0m ]\n\u001b[1;32m 788\u001b[0m non_state_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 789\u001b[0m c \u001b[38;5;28;01mfor\u001b[39;00m c \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_components \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(c, State)\n\u001b[1;32m 790\u001b[0m ]\n\u001b[0;32m--> 791\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mexamples_handler \u001b[38;5;241m=\u001b[39m \u001b[43mExamples\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 792\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 793\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnon_state_inputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n\u001b[1;32m 794\u001b[0m \u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnon_state_outputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n\u001b[1;32m 795\u001b[0m \u001b[43m \u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 796\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_examples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcache_examples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 797\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples_per_page\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexamples_per_page\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 798\u001b[0m \u001b[43m \u001b[49m\u001b[43m_api_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 799\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 800\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
|
99 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:54\u001b[0m, in \u001b[0;36mcreate_examples\u001b[0;34m(examples, inputs, outputs, fn, cache_examples, examples_per_page, _api_mode, label, elem_id, run_on_click, preprocess, postprocess, batch)\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate_examples\u001b[39m(\n\u001b[1;32m 39\u001b[0m examples: List[Any] \u001b[38;5;241m|\u001b[39m List[List[Any]] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28mstr\u001b[39m,\n\u001b[1;32m 40\u001b[0m inputs: IOComponent \u001b[38;5;241m|\u001b[39m List[IOComponent],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 51\u001b[0m batch: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 52\u001b[0m ):\n\u001b[1;32m 53\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Top-level synchronous function that creates Examples. Provided for backwards compatibility, i.e. so that gr.Examples(...) can be used to create the Examples component.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 54\u001b[0m examples_obj \u001b[38;5;241m=\u001b[39m \u001b[43mExamples\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 55\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 56\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 57\u001b[0m \u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moutputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 58\u001b[0m \u001b[43m \u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 59\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_examples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_examples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples_per_page\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples_per_page\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 61\u001b[0m \u001b[43m \u001b[49m\u001b[43m_api_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_api_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[43m \u001b[49m\u001b[43mlabel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 63\u001b[0m \u001b[43m \u001b[49m\u001b[43melem_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43melem_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 64\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_on_click\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_on_click\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 65\u001b[0m \u001b[43m \u001b[49m\u001b[43mpreprocess\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpreprocess\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 66\u001b[0m \u001b[43m \u001b[49m\u001b[43mpostprocess\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpostprocess\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 68\u001b[0m \u001b[43m \u001b[49m\u001b[43m_initiated_directly\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 69\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 70\u001b[0m utils\u001b[38;5;241m.\u001b[39msynchronize_async(examples_obj\u001b[38;5;241m.\u001b[39mcreate)\n\u001b[1;32m 71\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m examples_obj\n",
|
100 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:201\u001b[0m, in \u001b[0;36mExamples.__init__\u001b[0;34m(self, examples, inputs, outputs, fn, cache_examples, examples_per_page, _api_mode, label, elem_id, run_on_click, preprocess, postprocess, batch, _initiated_directly)\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[0;32m--> 201\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 202\u001b[0m [\n\u001b[1;32m 203\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 209\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n",
|
101 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:202\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m--> 202\u001b[0m [\n\u001b[1;32m 203\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 209\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n",
|
102 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:203\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 202\u001b[0m [\n\u001b[0;32m--> 203\u001b[0m \u001b[43mcomponent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpostprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43msample\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 204\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 209\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 210\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n",
|
103 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/components.py:1634\u001b[0m, in \u001b[0;36mImage.postprocess\u001b[0;34m(self, y)\u001b[0m\n\u001b[1;32m 1632\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m processing_utils\u001b[38;5;241m.\u001b[39mencode_pil_to_base64(y)\n\u001b[1;32m 1633\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(y, (\u001b[38;5;28mstr\u001b[39m, Path)):\n\u001b[0;32m-> 1634\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mprocessing_utils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencode_url_or_file_to_base64\u001b[49m\u001b[43m(\u001b[49m\u001b[43my\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1635\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1636\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot process this value as an Image\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
104 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/processing_utils.py:70\u001b[0m, in \u001b[0;36mencode_url_or_file_to_base64\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m encode_url_to_base64(path)\n\u001b[1;32m 69\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 70\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mencode_file_to_base64\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m)\u001b[49m\n",
|
105 |
+
"File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/processing_utils.py:94\u001b[0m, in \u001b[0;36mencode_file_to_base64\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mencode_file_to_base64\u001b[39m(f):\n\u001b[0;32m---> 94\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[1;32m 95\u001b[0m encoded_string \u001b[38;5;241m=\u001b[39m base64\u001b[38;5;241m.\u001b[39mb64encode(file\u001b[38;5;241m.\u001b[39mread())\n\u001b[1;32m 96\u001b[0m base64_str \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mstr\u001b[39m(encoded_string, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mutf-8\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
106 |
+
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'basketball.png'"
|
107 |
+
]
|
108 |
+
}
|
109 |
+
],
|
110 |
+
"source": [
|
111 |
+
"#|export\n",
|
112 |
+
"image = gr.components.Image(shape=(192,192))\n",
|
113 |
+
"label = gr.components.Label()\n",
|
114 |
+
"examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']\n",
|
115 |
+
"\n",
|
116 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
|
117 |
+
"intf.launch(inline=False)"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"cell_type": "code",
|
122 |
+
"execution_count": 4,
|
123 |
+
"metadata": {},
|
124 |
+
"outputs": [],
|
125 |
+
"source": [
|
126 |
+
"import nbdev\n",
|
127 |
+
"nbdev.export.nb_export('app.ipynb', 'app2')"
|
128 |
+
]
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"cell_type": "code",
|
132 |
+
"execution_count": null,
|
133 |
+
"metadata": {},
|
134 |
+
"outputs": [],
|
135 |
+
"source": []
|
136 |
+
}
|
137 |
+
],
|
138 |
+
"metadata": {
|
139 |
+
"kernelspec": {
|
140 |
+
"display_name": "Python 3 (ipykernel)",
|
141 |
+
"language": "python",
|
142 |
+
"name": "python3"
|
143 |
+
},
|
144 |
+
"language_info": {
|
145 |
+
"codemirror_mode": {
|
146 |
+
"name": "ipython",
|
147 |
+
"version": 3
|
148 |
+
},
|
149 |
+
"file_extension": ".py",
|
150 |
+
"mimetype": "text/x-python",
|
151 |
+
"name": "python",
|
152 |
+
"nbconvert_exporter": "python",
|
153 |
+
"pygments_lexer": "ipython3",
|
154 |
+
"version": "3.10.9"
|
155 |
+
}
|
156 |
+
},
|
157 |
+
"nbformat": 4,
|
158 |
+
"nbformat_minor": 2
|
159 |
+
}
|
.ipynb_checkpoints/load_data-checkpoint.ipynb
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"id": "c168f24a",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"!pip install -Uqq fastai duckduckgo_search pandas"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 5,
|
16 |
+
"id": "c84aa916",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"from duckduckgo_search import ddg_images\n",
|
21 |
+
"from fastcore.all import *\n",
|
22 |
+
"from time import sleep\n",
|
23 |
+
"import pandas as pd\n",
|
24 |
+
"from io import StringIO\n",
|
25 |
+
"\n",
|
26 |
+
"\n",
|
27 |
+
"def search_images(term, max_images=50):\n",
|
28 |
+
" print(f\"Searching for '{term}'\")\n",
|
29 |
+
" return L(ddg_images(term, max_results=max_images)).itemgot('image')"
|
30 |
+
]
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"cell_type": "code",
|
34 |
+
"execution_count": null,
|
35 |
+
"id": "fef32513",
|
36 |
+
"metadata": {},
|
37 |
+
"outputs": [],
|
38 |
+
"source": [
|
39 |
+
"df = pd.read_csv('')"
|
40 |
+
]
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "code",
|
44 |
+
"execution_count": null,
|
45 |
+
"id": "a17948bf",
|
46 |
+
"metadata": {},
|
47 |
+
"outputs": [],
|
48 |
+
"source": [
|
49 |
+
"searches = 'basketball ball','rugby ball', 'soccer ball', 'golf ball'\n",
|
50 |
+
"path = Path('model_pics')"
|
51 |
+
]
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"cell_type": "code",
|
55 |
+
"execution_count": null,
|
56 |
+
"id": "a78f7280",
|
57 |
+
"metadata": {},
|
58 |
+
"outputs": [],
|
59 |
+
"source": [
|
60 |
+
"\n",
|
61 |
+
"\n",
|
62 |
+
"\n",
|
63 |
+
"for o in searches:\n",
|
64 |
+
" dest = (path/o)\n",
|
65 |
+
" dest.mkdir(exist_ok=True, parents=True)\n",
|
66 |
+
" download_images(dest, urls=search_images(f'{o} photo'))\n",
|
67 |
+
" sleep(10) # Pause between searches to avoid over-loading server"
|
68 |
+
]
|
69 |
+
}
|
70 |
+
],
|
71 |
+
"metadata": {
|
72 |
+
"kernelspec": {
|
73 |
+
"display_name": "Python 3 (ipykernel)",
|
74 |
+
"language": "python",
|
75 |
+
"name": "python3"
|
76 |
+
},
|
77 |
+
"language_info": {
|
78 |
+
"codemirror_mode": {
|
79 |
+
"name": "ipython",
|
80 |
+
"version": 3
|
81 |
+
},
|
82 |
+
"file_extension": ".py",
|
83 |
+
"mimetype": "text/x-python",
|
84 |
+
"name": "python",
|
85 |
+
"nbconvert_exporter": "python",
|
86 |
+
"pygments_lexer": "ipython3",
|
87 |
+
"version": "3.10.9"
|
88 |
+
}
|
89 |
+
},
|
90 |
+
"nbformat": 4,
|
91 |
+
"nbformat_minor": 5
|
92 |
+
}
|
.ipynb_checkpoints/pre-process-checkpoint.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
Runpod.ipynb
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"id": "fccb1a4c",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"!pip install -Uqq fastai pandas gdown zipfile"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": null,
|
16 |
+
"id": "a07a5ad4",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"from fastcore.all import *\n",
|
21 |
+
"from fastai.vision.all import *\n",
|
22 |
+
"from time import sleep\n",
|
23 |
+
"import pandas as pd\n",
|
24 |
+
"from io import StringIO\n",
|
25 |
+
"import gdown\n",
|
26 |
+
"import zipfile"
|
27 |
+
]
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"cell_type": "code",
|
31 |
+
"execution_count": null,
|
32 |
+
"id": "5ace4a07",
|
33 |
+
"metadata": {},
|
34 |
+
"outputs": [],
|
35 |
+
"source": [
|
36 |
+
"file_id = \"YOUR_FILE_ID\"\n",
|
37 |
+
"url = f'https://drive.google.com/uc?id={file_id}'\n",
|
38 |
+
"output = 'images.zip'\n",
|
39 |
+
"gdown.download(url, output, quiet=False)"
|
40 |
+
]
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"cell_type": "code",
|
44 |
+
"execution_count": null,
|
45 |
+
"id": "95f78949",
|
46 |
+
"metadata": {},
|
47 |
+
"outputs": [],
|
48 |
+
"source": [
|
49 |
+
"with zipfile.ZipFile('images.zip', 'r') as zip_ref:\n",
|
50 |
+
" zip_ref.extractall('images')"
|
51 |
+
]
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"cell_type": "code",
|
55 |
+
"execution_count": null,
|
56 |
+
"id": "8558997b",
|
57 |
+
"metadata": {},
|
58 |
+
"outputs": [],
|
59 |
+
"source": [
|
60 |
+
"path = Path('images')\n",
|
61 |
+
"\n",
|
62 |
+
"dls = DataBlock(\n",
|
63 |
+
" blocks=(ImageBlock, CategoryBlock), \n",
|
64 |
+
" get_items=get_image_files, \n",
|
65 |
+
" splitter=RandomSplitter(valid_pct=0.2, seed=42),\n",
|
66 |
+
" get_y=parent_label,\n",
|
67 |
+
" item_tfms=[Resize(192, method='squish')]\n",
|
68 |
+
").dataloaders(path, bs=64)\n",
|
69 |
+
"\n",
|
70 |
+
"dls.show_batch(max_n=6)"
|
71 |
+
]
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"cell_type": "code",
|
75 |
+
"execution_count": null,
|
76 |
+
"id": "b6d7f347",
|
77 |
+
"metadata": {},
|
78 |
+
"outputs": [],
|
79 |
+
"source": [
|
80 |
+
"learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
|
81 |
+
"learn.fine_tune(5)"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": null,
|
87 |
+
"id": "ca176cad",
|
88 |
+
"metadata": {},
|
89 |
+
"outputs": [],
|
90 |
+
"source": [
|
91 |
+
"learn.export('model.pkl')"
|
92 |
+
]
|
93 |
+
}
|
94 |
+
],
|
95 |
+
"metadata": {
|
96 |
+
"kernelspec": {
|
97 |
+
"display_name": "Python 3 (ipykernel)",
|
98 |
+
"language": "python",
|
99 |
+
"name": "python3"
|
100 |
+
},
|
101 |
+
"language_info": {
|
102 |
+
"codemirror_mode": {
|
103 |
+
"name": "ipython",
|
104 |
+
"version": 3
|
105 |
+
},
|
106 |
+
"file_extension": ".py",
|
107 |
+
"mimetype": "text/x-python",
|
108 |
+
"name": "python",
|
109 |
+
"nbconvert_exporter": "python",
|
110 |
+
"pygments_lexer": "ipython3",
|
111 |
+
"version": "3.10.9"
|
112 |
+
}
|
113 |
+
},
|
114 |
+
"nbformat": 4,
|
115 |
+
"nbformat_minor": 5
|
116 |
+
}
|
app.ipynb
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"#|default_exp app2"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": 2,
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"#|export\n",
|
19 |
+
"from fastai.vision.all import *\n",
|
20 |
+
"import gradio as gr\n",
|
21 |
+
"import io\n",
|
22 |
+
"from PIL import Image\n",
|
23 |
+
"\n",
|
24 |
+
"def pet_class(x): return x"
|
25 |
+
]
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"cell_type": "code",
|
29 |
+
"execution_count": 3,
|
30 |
+
"metadata": {},
|
31 |
+
"outputs": [],
|
32 |
+
"source": [
|
33 |
+
"#|export\n",
|
34 |
+
"learn = load_learner('model.pkl')"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 12,
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"#|export\n",
|
44 |
+
"#categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')\n",
|
45 |
+
"\n",
|
46 |
+
"def classify_image(img, top_k=5):\n",
|
47 |
+
" pred_class, pred_idx, probs = learn.predict(img)\n",
|
48 |
+
" categories = learn.dls.vocab\n",
|
49 |
+
" sorted_probs_indices = probs.argsort(descending=True)\n",
|
50 |
+
" top_categories = [categories[i] for i in sorted_probs_indices[:top_k]]\n",
|
51 |
+
" top_probs = probs[sorted_probs_indices[:top_k]]\n",
|
52 |
+
" return dict(zip(top_categories, map(float, top_probs)))"
|
53 |
+
]
|
54 |
+
},
|
55 |
+
{
|
56 |
+
"cell_type": "code",
|
57 |
+
"execution_count": 13,
|
58 |
+
"metadata": {},
|
59 |
+
"outputs": [
|
60 |
+
{
|
61 |
+
"name": "stdout",
|
62 |
+
"output_type": "stream",
|
63 |
+
"text": [
|
64 |
+
"Running on local URL: http://127.0.0.1:7863\n",
|
65 |
+
"\n",
|
66 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
67 |
+
]
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"data": {
|
71 |
+
"text/plain": []
|
72 |
+
},
|
73 |
+
"execution_count": 13,
|
74 |
+
"metadata": {},
|
75 |
+
"output_type": "execute_result"
|
76 |
+
},
|
77 |
+
{
|
78 |
+
"data": {
|
79 |
+
"text/html": [
|
80 |
+
"\n",
|
81 |
+
"<style>\n",
|
82 |
+
" /* Turns off some styling */\n",
|
83 |
+
" progress {\n",
|
84 |
+
" /* gets rid of default border in Firefox and Opera. */\n",
|
85 |
+
" border: none;\n",
|
86 |
+
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
|
87 |
+
" background-size: auto;\n",
|
88 |
+
" }\n",
|
89 |
+
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
|
90 |
+
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
|
91 |
+
" }\n",
|
92 |
+
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
|
93 |
+
" background: #F44336;\n",
|
94 |
+
" }\n",
|
95 |
+
"</style>\n"
|
96 |
+
],
|
97 |
+
"text/plain": [
|
98 |
+
"<IPython.core.display.HTML object>"
|
99 |
+
]
|
100 |
+
},
|
101 |
+
"metadata": {},
|
102 |
+
"output_type": "display_data"
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"data": {
|
106 |
+
"text/html": [],
|
107 |
+
"text/plain": [
|
108 |
+
"<IPython.core.display.HTML object>"
|
109 |
+
]
|
110 |
+
},
|
111 |
+
"metadata": {},
|
112 |
+
"output_type": "display_data"
|
113 |
+
}
|
114 |
+
],
|
115 |
+
"source": [
|
116 |
+
"#|export\n",
|
117 |
+
"image = gr.components.Image(shape=(192,192))\n",
|
118 |
+
"label = gr.components.Label()\n",
|
119 |
+
"#examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']\n",
|
120 |
+
"\n",
|
121 |
+
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n",
|
122 |
+
"intf.launch(inline=False)"
|
123 |
+
]
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"execution_count": 4,
|
128 |
+
"metadata": {},
|
129 |
+
"outputs": [],
|
130 |
+
"source": [
|
131 |
+
"import nbdev\n",
|
132 |
+
"nbdev.export.nb_export('app.ipynb', 'app2')"
|
133 |
+
]
|
134 |
+
},
|
135 |
+
{
|
136 |
+
"cell_type": "code",
|
137 |
+
"execution_count": null,
|
138 |
+
"metadata": {},
|
139 |
+
"outputs": [],
|
140 |
+
"source": []
|
141 |
+
}
|
142 |
+
],
|
143 |
+
"metadata": {
|
144 |
+
"kernelspec": {
|
145 |
+
"display_name": "Python 3 (ipykernel)",
|
146 |
+
"language": "python",
|
147 |
+
"name": "python3"
|
148 |
+
},
|
149 |
+
"language_info": {
|
150 |
+
"codemirror_mode": {
|
151 |
+
"name": "ipython",
|
152 |
+
"version": 3
|
153 |
+
},
|
154 |
+
"file_extension": ".py",
|
155 |
+
"mimetype": "text/x-python",
|
156 |
+
"name": "python",
|
157 |
+
"nbconvert_exporter": "python",
|
158 |
+
"pygments_lexer": "ipython3",
|
159 |
+
"version": "3.10.9"
|
160 |
+
}
|
161 |
+
},
|
162 |
+
"nbformat": 4,
|
163 |
+
"nbformat_minor": 2
|
164 |
+
}
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'image', 'label', 'intf', 'pet_class', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
import io
|
10 |
+
from PIL import Image
|
11 |
+
|
12 |
+
def pet_class(x): return x
|
13 |
+
|
14 |
+
# %% ../app.ipynb 2
|
15 |
+
learn = load_learner('model.pkl')
|
16 |
+
|
17 |
+
# %% ../app.ipynb 3
|
18 |
+
#categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')
|
19 |
+
|
20 |
+
def classify_image(img, top_k=5):
|
21 |
+
pred_class, pred_idx, probs = learn.predict(img)
|
22 |
+
categories = learn.dls.vocab
|
23 |
+
sorted_probs_indices = probs.argsort(descending=True)
|
24 |
+
top_categories = [categories[i] for i in sorted_probs_indices[:top_k]]
|
25 |
+
top_probs = probs[sorted_probs_indices[:top_k]]
|
26 |
+
return dict(zip(top_categories, map(float, top_probs)))
|
27 |
+
|
28 |
+
# %% ../app.ipynb 4
|
29 |
+
image = gr.components.Image(shape=(192,192))
|
30 |
+
label = gr.components.Label()
|
31 |
+
#examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']
|
32 |
+
|
33 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
|
34 |
+
intf.launch(inline=False)
|
data_loader.ipynb
ADDED
File without changes
|
load_data.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1de42c0ea0bbe72b6a61d630f379d239ac3a915b353a0dbff4534e0f7dd0d680
|
3 |
+
size 244375721
|