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