Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
import PIL.Image
|
4 |
|
5 |
-
# Load
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
labels = learn.dls.vocab
|
10 |
|
11 |
-
# Define
|
12 |
-
def
|
13 |
-
img = PILImage.create(img)
|
14 |
pred, pred_idx, probs = learn.predict(img)
|
15 |
-
return {
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
inputs=gr.Image(),
|
25 |
-
outputs=gr.Label(num_top_classes=3),
|
26 |
-
title=title,
|
27 |
-
description=description,
|
28 |
-
article=article,
|
29 |
-
enable_queue=True).launch()
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
|
|
3 |
|
4 |
+
# Load your trained model
|
5 |
+
def load_model():
|
6 |
+
path = 'export.pkl'
|
7 |
+
learn = load_learner(path)
|
8 |
+
return learn
|
9 |
|
10 |
+
learn = load_model()
|
|
|
11 |
|
12 |
+
# Define prediction function
|
13 |
+
def predict_image(img):
|
|
|
14 |
pred, pred_idx, probs = learn.predict(img)
|
15 |
+
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(learn.dls.vocab))}
|
16 |
|
17 |
+
# Create a Gradio interface
|
18 |
+
interface = gr.Interface(fn=predict_image,
|
19 |
+
inputs=gr.inputs.Image(type="pil"),
|
20 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
21 |
+
title="Image Classifier",
|
22 |
+
description="Upload an image to classify.")
|
23 |
|
24 |
+
if __name__ == "__main__":
|
25 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|