matdmiller commited on
Commit
a892385
1 Parent(s): d5aaf1e

initial app commit

Browse files
Files changed (3) hide show
  1. app.ipynb +133 -0
  2. app.py +0 -0
  3. requirements.txt +1 -0
app.ipynb ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "d2c2b738",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from fastai.vision.all import *\n",
11
+ "import gradio as gr"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "id": "b92d24f3",
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": [
21
+ "# search_terms = ('hard hat','construction gloves','safety glasses','construction boots', 'screw driver','hammer','f150')\n"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 3,
27
+ "id": "34ebdca4",
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "# path = Path('construction_photos')"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 4,
37
+ "id": "04347f65",
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "source": [
41
+ "# dls = DataBlock(\n",
42
+ "# blocks=(ImageBlock,CategoryBlock),\n",
43
+ "# getters=None,\n",
44
+ "# n_inp=None,\n",
45
+ "# item_tfms=[Resize(224,method='squish')],\n",
46
+ "# get_items=get_image_files,\n",
47
+ "# splitter=RandomSplitter(seed=42),\n",
48
+ "# get_y=parent_label,\n",
49
+ "# ).dataloaders(path,bs=128)"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 5,
55
+ "id": "85098e65",
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": [
59
+ "learn = load_learner('construction_things.pkl')"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 6,
65
+ "id": "a6ed198b",
66
+ "metadata": {},
67
+ "outputs": [],
68
+ "source": [
69
+ "def classify_image(img):\n",
70
+ " pred,idx,probs = learn.predict(img)\n",
71
+ " return dict(zip(dls.vocab,map(float,probs)))\n",
72
+ "# classify_image(get_image_files(path)[100])"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 7,
78
+ "id": "b2f582a8",
79
+ "metadata": {},
80
+ "outputs": [
81
+ {
82
+ "name": "stdout",
83
+ "output_type": "stream",
84
+ "text": [
85
+ "Running on local URL: http://127.0.0.1:7860/\n",
86
+ "\n",
87
+ "To create a public link, set `share=True` in `launch()`.\n"
88
+ ]
89
+ },
90
+ {
91
+ "data": {
92
+ "text/plain": [
93
+ "(<fastapi.applications.FastAPI at 0x7ff6a8761430>,\n",
94
+ " 'http://127.0.0.1:7860/',\n",
95
+ " None)"
96
+ ]
97
+ },
98
+ "execution_count": 7,
99
+ "metadata": {},
100
+ "output_type": "execute_result"
101
+ }
102
+ ],
103
+ "source": [
104
+ "image = gr.inputs.Image(shape=(192,192))\n",
105
+ "label = gr.outputs.Label()\n",
106
+ "interface = gr.Interface(fn=classify_image,inputs=image,outputs=label)\n",
107
+ "# interface.launch(inline=True)\n",
108
+ "interface.launch(inline=False)"
109
+ ]
110
+ }
111
+ ],
112
+ "metadata": {
113
+ "kernelspec": {
114
+ "display_name": "Python 3 (ipykernel)",
115
+ "language": "python",
116
+ "name": "python3"
117
+ },
118
+ "language_info": {
119
+ "codemirror_mode": {
120
+ "name": "ipython",
121
+ "version": 3
122
+ },
123
+ "file_extension": ".py",
124
+ "mimetype": "text/x-python",
125
+ "name": "python",
126
+ "nbconvert_exporter": "python",
127
+ "pygments_lexer": "ipython3",
128
+ "version": "3.9.7"
129
+ }
130
+ },
131
+ "nbformat": 4,
132
+ "nbformat_minor": 5
133
+ }
app.py ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai