Spaces:
Runtime error
Runtime error
Commit ·
75cc15b
1
Parent(s): f3300ac
huggingspace - linux - upload
Browse files- app.py +30 -0
- export.pkl +3 -0
- images/riverotter.jpg +0 -0
- images/seaotter.jpg +0 -0
- images/stuffedotter.jpg +0 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['is_sea','learn','classify_image','categories','image','label','examples','intf']
|
| 2 |
+
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import pathlib
|
| 6 |
+
import platform
|
| 7 |
+
|
| 8 |
+
def is_sea(x) : return x[0].isupper()
|
| 9 |
+
|
| 10 |
+
# Check the platform
|
| 11 |
+
plt = platform.system()
|
| 12 |
+
|
| 13 |
+
# If the platform is Linux, redirect WindowsPath to PosixPath
|
| 14 |
+
if plt == 'Linux':
|
| 15 |
+
pathlib.WindowsPath = pathlib.PosixPath
|
| 16 |
+
|
| 17 |
+
learn = load_learner('export.pkl')
|
| 18 |
+
|
| 19 |
+
categories = ('River', "Sea", "Stuffed")
|
| 20 |
+
|
| 21 |
+
def classify_image(img):
|
| 22 |
+
pred,idx,probs = learn.predict(img)
|
| 23 |
+
return dict(zip(categories,map(float,probs)))
|
| 24 |
+
|
| 25 |
+
image = gr.inputs.Image(shape = (192,192))
|
| 26 |
+
label = gr.outputs.Label()
|
| 27 |
+
examples = ['images/seaotter.jpg' , 'images/riverotter.jpg' , 'images/stuffedotter.jpg']
|
| 28 |
+
|
| 29 |
+
intf = gr.Interface(fn=classify_image, inputs=image,outputs=label,examples=examples)
|
| 30 |
+
intf.launch(inline=False)
|
export.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e10c6528e60ee2d78f1197ff60aad8c2989e969b49a6249911526b00b1558664
|
| 3 |
+
size 46971454
|
images/riverotter.jpg
ADDED
|
images/seaotter.jpg
ADDED
|
images/stuffedotter.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
gradio
|
| 3 |
+
pathlib
|
| 4 |
+
platform
|