Spaces:
Sleeping
Sleeping
Gabriel
commited on
Commit
·
bbab302
1
Parent(s):
ce243af
feat: app and requirements
Browse files- app.py +27 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## importing dependencies
|
2 |
+
import gradio as gr
|
3 |
+
from fastai.vision.all import *
|
4 |
+
|
5 |
+
## importing model created
|
6 |
+
learn = load_learner('model.pkl')
|
7 |
+
|
8 |
+
## creating labels and examples to be used by the interface
|
9 |
+
labels = learn.dls.vocab
|
10 |
+
examples = ['stop_sign.png',
|
11 |
+
'pedestrian_crossing_sign.png',
|
12 |
+
'speed_limit_sign.png',
|
13 |
+
'bump_sign.png',
|
14 |
+
'semaphore_sign.png']
|
15 |
+
|
16 |
+
## creating prediction function for the interface
|
17 |
+
def predict(img):
|
18 |
+
img = PILImage.create(img)
|
19 |
+
pred, pred_idx, probability = learn.predict(img)
|
20 |
+
return {labels[i]: float(probability[i]) for i in range(len(labels))}
|
21 |
+
|
22 |
+
## generating huggingFace's interface
|
23 |
+
gr.Interface(fn=predict,
|
24 |
+
inputs=gr.components.Image(shape=(512, 512)),
|
25 |
+
outputs=gr.components.Label(num_top_classes=3),
|
26 |
+
examples=examples
|
27 |
+
).launch(share=False)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|