Spaces:
Sleeping
Sleeping
ni6670154@gmail.com
commited on
Commit
·
fda413d
1
Parent(s):
ff7edfb
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import pathlib
|
5 |
+
temp = pathlib.PosixPath
|
6 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
7 |
+
|
8 |
+
# Provide the full path to the model file
|
9 |
+
model_path = 'models/vehicle-recognizer-v2.pkl'
|
10 |
+
model = load_learner(model_path)
|
11 |
+
|
12 |
+
cap_labels = model.dls.vocab
|
13 |
+
|
14 |
+
def recognize_image(image):
|
15 |
+
pred, idx, probs = model.predict(image)
|
16 |
+
return dict(zip(cap_labels, map(float, probs)))
|
17 |
+
|
18 |
+
image_input = gr.Image()
|
19 |
+
label_output = gr.Label()
|
20 |
+
|
21 |
+
examples = [
|
22 |
+
'test_images/bus.jpg',
|
23 |
+
'test_images/car.jpg',
|
24 |
+
'test_images/helicopter.jpg',
|
25 |
+
'test_images/plane.jpg'
|
26 |
+
]
|
27 |
+
|
28 |
+
iface = gr.Interface(fn=recognize_image, inputs=image_input, outputs=label_output, examples=examples)
|
29 |
+
iface.launch(inline=False)
|