李根赢 commited on
Commit
1335d7c
1 Parent(s): 038a1fb

add app.py

Browse files
Files changed (5) hide show
  1. .ipynb_checkpoints/app-checkpoint.ipynb +82 -0
  2. app.ipynb +140 -0
  3. app.py +16 -4
  4. bear.jpg +0 -0
  5. export.pkl +3 -0
.ipynb_checkpoints/app-checkpoint.ipynb ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# /default_exp app"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": null,
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": null,
26
+ "metadata": {},
27
+ "outputs": [],
28
+ "source": [
29
+ "learn = load_learner('model.pkl')"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": null,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": []
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": null,
42
+ "metadata": {},
43
+ "outputs": [],
44
+ "source": []
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": null,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": []
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": null,
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": []
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": null,
63
+ "metadata": {},
64
+ "outputs": [],
65
+ "source": []
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": null,
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": []
73
+ }
74
+ ],
75
+ "metadata": {
76
+ "language_info": {
77
+ "name": "python"
78
+ }
79
+ },
80
+ "nbformat": 4,
81
+ "nbformat_minor": 2
82
+ }
app.ipynb ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 7,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "ename": "ModuleNotFoundError",
10
+ "evalue": "No module named 'fastbook'",
11
+ "output_type": "error",
12
+ "traceback": [
13
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
14
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
15
+ "\u001b[1;32m/home/ghost/pythoncode/bear_classifier/app.ipynb Cell 1\u001b[0m line \u001b[0;36m2\n\u001b[1;32m <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W0sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m get_ipython()\u001b[39m.\u001b[39msystem(\u001b[39m'\u001b[39m\u001b[39m [ -e /content ] && pip install -Uqq fastbook\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W0sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mfastbook\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W0sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m fastbook\u001b[39m.\u001b[39msetup_book()\n\u001b[1;32m <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W0sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mfastbook\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m\n",
16
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'fastbook'"
17
+ ]
18
+ }
19
+ ],
20
+ "source": [
21
+ "! [ -e /content ] && pip install -Uqq fastbook\n",
22
+ "import fastbook\n",
23
+ "fastbook.setup_book()\n",
24
+ "\n",
25
+ "from fastbook import *\n",
26
+ "from fastai.vision.widgets import *"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": 5,
32
+ "metadata": {},
33
+ "outputs": [
34
+ {
35
+ "name": "stdout",
36
+ "output_type": "stream",
37
+ "text": [
38
+ "\u001b[KFatal error from pip prevented installation. Full pip output in file:\n",
39
+ " /home/ghost/.local/pipx/logs/cmd_2024-03-08_10.04.53_pip_errors.log\n",
40
+ "\n",
41
+ "Some possibly relevant errors from pip install:\n",
42
+ " \u001b[0m\u001b[31mERROR: Could not find a version that satisfies the requirement gradio (from versions: none)\u001b[0m\u001b[31m\n",
43
+ " \u001b[0m\u001b[31mERROR: No matching distribution found for gradio\u001b[0m\u001b[31m\n",
44
+ "\n",
45
+ "Error installing gradio.\n",
46
+ "\u001b[?25h\u001b[0m"
47
+ ]
48
+ },
49
+ {
50
+ "ename": "ModuleNotFoundError",
51
+ "evalue": "No module named 'gradio'",
52
+ "output_type": "error",
53
+ "traceback": [
54
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
55
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
56
+ "\u001b[1;32m/home/ghost/pythoncode/bear_classifier/app.ipynb Cell 2\u001b[0m line \u001b[0;36m3\n\u001b[1;32m <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W1sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39m# export\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W1sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m get_ipython()\u001b[39m.\u001b[39msystem(\u001b[39m'\u001b[39m\u001b[39m pipx install gradio\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/ghost/pythoncode/bear_classifier/app.ipynb#W1sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mgradio\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mgr\u001b[39;00m\n",
57
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gradio'"
58
+ ]
59
+ }
60
+ ],
61
+ "source": [
62
+ "# export\n",
63
+ "! pipx install gradio\n",
64
+ "import gradio as gr"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": null,
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": [
73
+ "learn = load_learner('model.pkl')"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "code",
78
+ "execution_count": null,
79
+ "metadata": {},
80
+ "outputs": [],
81
+ "source": []
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": null,
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": []
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "metadata": {},
94
+ "outputs": [],
95
+ "source": []
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": []
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": null,
107
+ "metadata": {},
108
+ "outputs": [],
109
+ "source": []
110
+ },
111
+ {
112
+ "cell_type": "code",
113
+ "execution_count": null,
114
+ "metadata": {},
115
+ "outputs": [],
116
+ "source": []
117
+ }
118
+ ],
119
+ "metadata": {
120
+ "kernelspec": {
121
+ "display_name": "Python 3 (ipykernel)",
122
+ "language": "python",
123
+ "name": "python3"
124
+ },
125
+ "language_info": {
126
+ "codemirror_mode": {
127
+ "name": "ipython",
128
+ "version": 3
129
+ },
130
+ "file_extension": ".py",
131
+ "mimetype": "text/x-python",
132
+ "name": "python",
133
+ "nbconvert_exporter": "python",
134
+ "pygments_lexer": "ipython3",
135
+ "version": "3.11.8"
136
+ }
137
+ },
138
+ "nbformat": 4,
139
+ "nbformat_minor": 4
140
+ }
app.py CHANGED
@@ -1,7 +1,19 @@
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: gdrive/MyDrive/Colab Notebooks/Untitled8.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['path', 'learn_inf', 'btn_upload', 'pred', 'pred_idx', 'probs']
5
+
6
+ # %% gdrive/MyDrive/Colab Notebooks/Untitled8.ipynb 24
7
+ from fastai.vision.widgets import *
8
  import gradio as gr
9
 
10
+ # %% gdrive/MyDrive/Colab Notebooks/Untitled8.ipynb 25
11
+ # path = Path('bears')
12
+ learn_inf = load_learner('export.pkl')
13
+
14
+ # %% gdrive/MyDrive/Colab Notebooks/Untitled8.ipynb 26
15
+ btn_upload = widgets.FileUpload()
16
+ btn_upload
17
 
18
+ # %% gdrive/MyDrive/Colab Notebooks/Untitled8.ipynb 30
19
+ pred,pred_idx,probs = learn_inf.predict(img)
bear.jpg ADDED
export.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64fcc399f6556d2c54c26d69344310010ac3d9a024b9926fb0bf1a5838eade6d
3
+ size 46969470