Spaces:
Sleeping
Sleeping
jorgenlybeck
commited on
Commit
•
929ad8c
1
Parent(s):
5799735
add label again
Browse files
app.py
CHANGED
@@ -4,27 +4,22 @@ 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_wolverine(x):
|
9 |
-
return x[0].isupper() #
|
10 |
|
11 |
import sys
|
12 |
sys.modules["__main__"].is_wolverine = is_wolverine
|
13 |
|
14 |
-
# Upload your model
|
15 |
learn = load_learner('model.pkl')
|
16 |
-
|
17 |
categories = learn.dls.vocab
|
18 |
|
19 |
def classify_image(img):
|
20 |
-
pred,idx,probs = learn.predict(img)
|
21 |
-
return
|
22 |
|
23 |
image = gr.Image()
|
24 |
-
label = gr.
|
25 |
|
26 |
-
# Upload your own images and link them
|
27 |
examples = ['./examples/wolverine.jpg', './examples/bear.jpg', './examples/bear_or_wolverine.jpg']
|
28 |
-
|
29 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
30 |
-
intf.launch()
|
|
|
4 |
import gradio as gr
|
5 |
import timm
|
6 |
|
|
|
7 |
def is_wolverine(x):
|
8 |
+
return x[0].isupper() # Custom logic for model
|
9 |
|
10 |
import sys
|
11 |
sys.modules["__main__"].is_wolverine = is_wolverine
|
12 |
|
|
|
13 |
learn = load_learner('model.pkl')
|
|
|
14 |
categories = learn.dls.vocab
|
15 |
|
16 |
def classify_image(img):
|
17 |
+
pred, idx, probs = learn.predict(img)
|
18 |
+
return f"This is a {pred}" # Modified output format
|
19 |
|
20 |
image = gr.Image()
|
21 |
+
label = gr.Textbox() # Changed to Textbox for string output
|
22 |
|
|
|
23 |
examples = ['./examples/wolverine.jpg', './examples/bear.jpg', './examples/bear_or_wolverine.jpg']
|
|
|
24 |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
25 |
+
intf.launch()
|