Spaces:
Running
Running
Add binary files, app.py and track with Git LFS
Browse files- .gitattributes +1 -0
- app.py +44 -0
- cat.jpg +3 -0
- dog.jpg +3 -0
- model.pkl +3 -0
- requirements.txt +1 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 6
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
+
|
12 |
+
|
13 |
+
# %% ../app.ipynb 9
|
14 |
+
#EXPORT_PATH = pathlib.Path("model.pkl")
|
15 |
+
|
16 |
+
#with set_posix_windows():
|
17 |
+
#learn = load_learner(EXPORT_PATH)
|
18 |
+
|
19 |
+
learn = load_learner('model.pkl')
|
20 |
+
|
21 |
+
# %% ../app.ipynb 11
|
22 |
+
categories = ('Dog', 'Cat')
|
23 |
+
def classify_image(img):
|
24 |
+
img = img.resize((192, 192))
|
25 |
+
img = PILImage.create(img)
|
26 |
+
|
27 |
+
if not isinstance(img, Image.Image):
|
28 |
+
return "Error: The input is not a valid image."
|
29 |
+
|
30 |
+
# Make the prediction using the pre-trained model
|
31 |
+
pred, idx, probs = learn.predict(img)
|
32 |
+
|
33 |
+
# Return the probabilities as a dictionary of categories and their respective probabilities
|
34 |
+
return dict(zip(categories, map(float, probs)))
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
# %% ../app.ipynb 13
|
39 |
+
image = gr.Image(type="pil")
|
40 |
+
label = gr.Label()
|
41 |
+
examples = ['dog.jpg', 'cat.jpg']
|
42 |
+
|
43 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
44 |
+
intf.launch(inline=False)
|
cat.jpg
ADDED
![]() |
Git LFS Details
|
dog.jpg
ADDED
![]() |
Git LFS Details
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
|
3 |
+
size 47059947
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai
|