Ski model
Browse files- app.py +27 -4
- requirements.txt +5 -0
- slope.jpg +0 -0
- track.jpeg +0 -0
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
2 |
+
|
3 |
+
from fastai.vision.all import *
|
4 |
import gradio as gr
|
5 |
+
import timm
|
6 |
+
|
7 |
+
# Some magic according to https://forums.fast.ai/t/lesson-2-official-topic/96033/376?page=17
|
8 |
+
def is_cat(x):
|
9 |
+
return x[0].isupper() # Used by model
|
10 |
+
|
11 |
+
import sys
|
12 |
+
sys.modules["__main__"].is_cat = is_cat
|
13 |
+
|
14 |
+
# Upload your model
|
15 |
+
learn = load_learner('/kaggle/input/xc-downhill/model.pkl')
|
16 |
+
|
17 |
+
categories = learn.dls.vocab
|
18 |
+
|
19 |
+
def classify_image(img):
|
20 |
+
pred,idx,probs = learn.predict(img)
|
21 |
+
return dict(zip(categories, map(float,probs)))
|
22 |
+
|
23 |
+
image = gr.Image()
|
24 |
+
label = gr.Label()
|
25 |
|
26 |
+
# Upload your own images and link them
|
27 |
+
examples = ['slope.jpg', 'track.jpeg']
|
28 |
|
29 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
30 |
+
intf.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
gradio
|
3 |
+
timm
|
4 |
+
torch
|
5 |
+
torchvision
|
slope.jpg
ADDED
track.jpeg
ADDED