Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,27 @@
|
|
1 |
|
2 |
-
|
|
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
title = "Minimal Gradio Example"
|
10 |
-
description = "This example demonstrates using Gradio with an image input and label output."
|
11 |
|
12 |
-
gr.Interface(
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
__all__ = ['learner', 'labels', 'interface', 'classify']
|
3 |
+
|
4 |
+
from fastai.vision.all import *
|
5 |
import gradio as gr
|
6 |
|
7 |
+
learner = load_learner('ConvNext_RmsProps.pkl')
|
8 |
+
|
9 |
+
labels = learner.dls.vocab
|
10 |
+
|
11 |
+
|
12 |
+
def classify(img):
|
13 |
+
img = PILImage.create(img)
|
14 |
+
pred, pred_idx, probs = learner.predict(img)
|
15 |
+
return {labels[i]: float(probs[i]) for i in range (len(labels))}
|
16 |
|
|
|
|
|
17 |
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=classify,
|
20 |
+
inputs=gr.Image(),
|
21 |
+
outputs=gr.Label(),
|
22 |
+
examples=['Amanita.jpg'],
|
23 |
+
allow_flagging='never',
|
24 |
+
title='Bear classifier',
|
25 |
+
description='Model trained to classify four types of bears — black, giant panda, red panda and polar.'
|
26 |
+
)
|
27 |
+
interface.launch(share=False, inline=False)
|