Spaces:
Runtime error
Runtime error
Joel Sleppy
commited on
Commit
β’
8446f22
1
Parent(s):
4285e3e
use LFS with only model.pkl?
Browse files- README.md +13 -3
- app.py +39 -3
- examples/disco.jpg +0 -0
- examples/scarlet_crown.jpg +0 -0
- examples/silver_torch.webp +0 -0
- requirements.txt +3 -3
README.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Cactus Classifier
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.1.7
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,3 +1,39 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
from fastai.learner import load_learner
|
7 |
+
|
8 |
+
|
9 |
+
learner = load_learner(Path("model.pkl"))
|
10 |
+
labels = learner.dls.vocab
|
11 |
+
|
12 |
+
|
13 |
+
def classify(image: np.array):
|
14 |
+
results = learner.predict(image)
|
15 |
+
probabilities = results[2]
|
16 |
+
probabilities = map(float, probabilities)
|
17 |
+
return dict(zip(labels, probabilities))
|
18 |
+
|
19 |
+
|
20 |
+
description = """<p>Give me a cactus picture and I'll try to guess the variety.</p>
|
21 |
+
<p>I can recognize the following types of cactus:</p>
|
22 |
+
<ul>
|
23 |
+
{list_items}
|
24 |
+
</ul>
|
25 |
+
<p>This model was trained <a href="https://www.kaggle.com/jdsleppy/cactus-classifier/">here</a> by <a href="https://www.joelsleppy.com">Joel</a>.</p>
|
26 |
+
""".format(
|
27 |
+
list_items='\n'.join([f' <li>{label}</li>' for label in labels])
|
28 |
+
)
|
29 |
+
|
30 |
+
|
31 |
+
gr.Interface(
|
32 |
+
fn=classify,
|
33 |
+
inputs="image",
|
34 |
+
outputs="label",
|
35 |
+
examples=["examples/disco.jpg", "examples/scarlet_crown.jpg", "examples/silver_torch.webp"],
|
36 |
+
title="Cactus Classifier",
|
37 |
+
description=description,
|
38 |
+
allow_flagging="never",
|
39 |
+
).launch()
|
examples/disco.jpg
CHANGED
Git LFS Details
|
examples/scarlet_crown.jpg
CHANGED
Git LFS Details
|
examples/silver_torch.webp
CHANGED
Git LFS Details
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
1 |
+
fastai==2.7.9
|
2 |
+
gradio==3.1.7
|
3 |
+
numpy==1.23.2
|