Spaces:
Runtime error
Runtime error
ryanleeme17
commited on
Commit
·
c0de0b3
1
Parent(s):
1d4f9d0
app.py in correct folder
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../dogvcat_test.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
| 5 |
+
|
| 6 |
+
# %% ../dogvcat_test.ipynb 2
|
| 7 |
+
learn = load_learner('model.pkl')
|
| 8 |
+
|
| 9 |
+
# %% ../dogvcat_test.ipynb 4
|
| 10 |
+
categories = ('Dog', 'Cat')
|
| 11 |
+
|
| 12 |
+
def classify_image(img):
|
| 13 |
+
pred,idx,probs = learn.predict(img)
|
| 14 |
+
#format the output of learn.predict. dict creates dictionary, zip associates the labels with the probabilities and map converts the tensor into a float
|
| 15 |
+
return dict(zip(categories, map(float,probs)))
|
| 16 |
+
|
| 17 |
+
# %% ../dogvcat_test.ipynb 6
|
| 18 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 19 |
+
label = gr.outputs.Label()
|
| 20 |
+
examples = ['dog.jpeg', 'cat.jpg', 'dunno.jpeg']
|
| 21 |
+
|
| 22 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 23 |
+
intf.launch(inline=False)
|
| 24 |
+
|