Spaces:
Running
Running
first model version
Browse files- .gitignore +9 -0
- app.py +33 -0
- images_examples/mona_lisa.jpg +0 -0
- images_examples/persistence_of_memory.jpg +0 -0
- images_examples/starry_night.jpg +0 -0
- model.pkl +3 -0
- requeriments.txt +1 -0
.gitignore
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# Environments
|
7 |
+
.env
|
8 |
+
.venv
|
9 |
+
|
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio import gr
|
2 |
+
from fastai.vision.all import load_learner
|
3 |
+
|
4 |
+
|
5 |
+
CATS_MAP = {
|
6 |
+
"picasso": "Pablo Picasso",
|
7 |
+
"vanGogh": "Vincent van Gogh",
|
8 |
+
"dali": "Salvador Dalí",
|
9 |
+
"daVinci": "Leonardo da Vinci",
|
10 |
+
"rembrandt": "Rembrandt",
|
11 |
+
}
|
12 |
+
|
13 |
+
# load pre-trained model
|
14 |
+
model = load_learner("model.pkl")
|
15 |
+
|
16 |
+
# get classes name in right order
|
17 |
+
full_name_cats = [CATS_MAP[key_class] for key_class in model.dls.vocab]
|
18 |
+
|
19 |
+
|
20 |
+
def classify_image(img) -> dict:
|
21 |
+
category, idx, probs = model.predict(img)
|
22 |
+
return dict(zip(full_name_cats, map(float, probs)))
|
23 |
+
|
24 |
+
|
25 |
+
# Gradio control
|
26 |
+
image = gr.inputs.Image(shape=(224, 224))
|
27 |
+
label = gr.outputs.Label()
|
28 |
+
examples = [
|
29 |
+
f"images_examples/{filename}" for filename in ("mona_lisa.jpg", "starry_night.jpg", "persistence_of_memory.jpg")
|
30 |
+
]
|
31 |
+
|
32 |
+
gui = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
33 |
+
gui.launch(inline=False)
|
images_examples/mona_lisa.jpg
ADDED
images_examples/persistence_of_memory.jpg
ADDED
images_examples/starry_night.jpg
ADDED
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bbf064109c0b0708b8bfc90933d485b67618f5de1dac974ede8bd35f99a451de
|
3 |
+
size 46975713
|
requeriments.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
fastai==2.7.10
|