Spaces:
Build error
Build error
initial commit
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
|
6 |
+
__all__ = ['load_learner', 'lean', 'greet', 'classify_image',
|
7 |
+
'image', 'label', 'examples', 'interface']
|
8 |
+
|
9 |
+
path = Path(__file__).parent
|
10 |
+
|
11 |
+
|
12 |
+
def greet(name):
|
13 |
+
return "Hello " + name + "!!"
|
14 |
+
|
15 |
+
|
16 |
+
learn_inf = load_learner(path/'plane.pkl')
|
17 |
+
# learn_inf.predict('test.png')
|
18 |
+
|
19 |
+
|
20 |
+
# print(learn_inf.predict('test.png'))
|
21 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
22 |
+
# iface.launch()
|
23 |
+
|
24 |
+
# categories = ['F-22 Raptor', 'SR-71 Blackbird', 'B-2 Spirit']
|
25 |
+
categories = learn_inf.dls.vocab
|
26 |
+
|
27 |
+
|
28 |
+
def classify_image(img):
|
29 |
+
pred, pred_idx, probs = learn_inf.predict(img)
|
30 |
+
return {categories[i]: float(probs[i]) for i in range(len(probs))}
|
31 |
+
|
32 |
+
|
33 |
+
image = gr.inputs.Image(shape=(224, 224))
|
34 |
+
label = gr.outputs.Label(num_top_classes=3)
|
35 |
+
|
36 |
+
|
37 |
+
examples = [['b2.jpg'], ['f22.jpg'], ['sr71.jpg']]
|
38 |
+
|
39 |
+
interface = gr.Interface(fn=classify_image, inputs=image,
|
40 |
+
outputs=label, examples=examples)
|
41 |
+
interface.launch(inline=False)
|
42 |
+
|
43 |
+
|
44 |
+
# print(learn_inf.predict('b2.jpg'))
|
b2.jpg
ADDED
f22.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastai
|
3 |
+
pathlib
|