tyler cross
commited on
Commit
•
2ad056f
1
Parent(s):
c63cda9
Trying another pathing
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +22 -10
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import pathlib
|
2 |
import platform
|
3 |
-
from fastai.vision.all import load_learner
|
4 |
import gradio as gr
|
|
|
|
|
5 |
|
6 |
-
# If the operating system is not Windows, we patch pathlib.WindowsPath to be pathlib.PosixPath
|
7 |
if platform.system() != 'Windows':
|
8 |
pathlib.WindowsPath = pathlib.PosixPath
|
9 |
|
@@ -11,15 +11,27 @@ EXPORT_PATH = "export.pkl"
|
|
11 |
learn_inf = load_learner(EXPORT_PATH)
|
12 |
|
13 |
def classify_image(img):
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
demo = gr.Interface(
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
)
|
|
|
23 |
|
24 |
if __name__ == "__main__":
|
25 |
-
demo.launch()
|
|
|
1 |
import pathlib
|
2 |
import platform
|
|
|
3 |
import gradio as gr
|
4 |
+
from fastai.vision.all import load_learner
|
5 |
+
from PIL import Image
|
6 |
|
|
|
7 |
if platform.system() != 'Windows':
|
8 |
pathlib.WindowsPath = pathlib.PosixPath
|
9 |
|
|
|
11 |
learn_inf = load_learner(EXPORT_PATH)
|
12 |
|
13 |
def classify_image(img):
|
14 |
+
"""Classifies an image according to three categories: dung beetle, elephant, or dolphin.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
img (any): Any image will be converted to expected type.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
_type_: Probabilies according to the three types.
|
21 |
+
"""
|
22 |
+
# Convert the image to a format the model expects
|
23 |
+
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
24 |
+
# Make a prediction
|
25 |
+
pred_class, pred_idx, probs = learn_inf.predict(img)
|
26 |
+
# Return the result
|
27 |
+
return {learn_inf.dls.vocab[i]: float(probs[i]) for i in range(len(learn_inf.dls.vocab))}
|
28 |
|
29 |
demo = gr.Interface(
|
30 |
+
title = "A dung beetle / dolphin / elephant image classifier",
|
31 |
+
fn=classify_image,
|
32 |
+
inputs = gr.Image(
|
33 |
+
label = 'Upload an image of a dung beetle, a dolphin, or an elephant!'),
|
34 |
+
outputs="label")
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
+
demo.launch()
|