Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
|
4 |
+
mapping = {'cat_counter/cat': 1.0, 'cat_counter/two cats': 2.0, 'cat_counter/three cats': 3.0}
|
5 |
+
|
6 |
+
def get_number_of_cats(file_name):
|
7 |
+
return mapping.get(str(file_name.parent), 0)
|
8 |
+
|
9 |
+
learn = load_learner('./cat_counter.pkl')
|
10 |
+
|
11 |
+
mapping = {'cat_counter/cat': 1.0, 'cat_counter/two cats': 2.0, 'cat_counter/three cats': 3.0}
|
12 |
+
|
13 |
+
def get_number_of_cats(file_name):
|
14 |
+
return mapping.get(str(file_name.parent), 0)
|
15 |
+
|
16 |
+
learn = load_learner('cat_counter.pkl')
|
17 |
+
|
18 |
+
def predict(img):
|
19 |
+
img = PILImage.create(img)
|
20 |
+
pred,pred_idx,probs = learn.predict(img)
|
21 |
+
print(type(probs))
|
22 |
+
return torch.round(probs)
|
23 |
+
|
24 |
+
title = "Cat Counter"
|
25 |
+
description = "A model that counts cats"
|
26 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs="number", title=title, description=description).launch(share=True)
|
27 |
+
|
28 |
+
|