Spaces:
Runtime error
Runtime error
MohammedAlakhras
commited on
Commit
•
1407cdc
1
Parent(s):
6e135e3
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,45 @@
|
|
1 |
-
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
|
2 |
-
|
3 |
-
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
4 |
import platform
|
5 |
import pathlib
|
6 |
plt = platform.system()
|
7 |
pathlib.WindowsPath = pathlib.PosixPath
|
8 |
-
|
9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
from fastai.vision.all import *
|
11 |
-
|
12 |
|
13 |
-
|
14 |
|
15 |
-
#
|
16 |
-
learn = load_learner('model.pkl')
|
17 |
|
18 |
-
#
|
19 |
-
categories
|
20 |
|
21 |
def classify_image(img):
|
22 |
-
pred,
|
23 |
-
return dict(zip(categories,
|
|
|
24 |
|
25 |
-
#
|
26 |
-
image
|
27 |
-
label
|
28 |
-
examples
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
1 |
import platform
|
2 |
import pathlib
|
3 |
plt = platform.system()
|
4 |
pathlib.WindowsPath = pathlib.PosixPath
|
5 |
+
|
6 |
+
#import subprocess
|
7 |
+
#import sys
|
8 |
+
|
9 |
+
#def install(package):
|
10 |
+
# subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
11 |
+
|
12 |
+
#install('fastbook')
|
13 |
+
|
14 |
+
|
15 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
16 |
+
|
17 |
+
# %% auto 0
|
18 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'interface', 'classify_image']
|
19 |
+
|
20 |
+
# %% app.ipynb 1
|
21 |
+
#from fastbook import *
|
22 |
+
|
23 |
from fastai.vision.all import *
|
24 |
+
from fastai.vision.widgets import ImageClassifierCleaner
|
25 |
|
26 |
+
import gradio as gr
|
27 |
|
28 |
+
# %% app.ipynb 2
|
29 |
+
learn = load_learner('./model.pkl')
|
30 |
|
31 |
+
# %% app.ipynb 3
|
32 |
+
categories=('bird','forest')
|
33 |
|
34 |
def classify_image(img):
|
35 |
+
pred,indx,probs=learn.predict(img)
|
36 |
+
return dict(zip(categories,map(float,probs)))
|
37 |
+
|
38 |
|
39 |
+
# %% app.ipynb 4
|
40 |
+
image=gr.inputs.Image(shape=(192,192))
|
41 |
+
label=gr.outputs.Label()
|
42 |
+
examples=['a.jpg', 'b.jpg','c.jpg','d.jpg']
|
43 |
|
44 |
+
interface=gr.Interface(fn=classify_image, inputs=image ,outputs=label,examples=examples)
|
45 |
+
interface.launch(inline=False)
|