Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
-
import skimage
|
4 |
from fastai.vision.all import PILImage
|
5 |
|
|
|
6 |
learn = load_learner('export.pkl')
|
7 |
|
|
|
8 |
labels = learn.dls.vocab
|
9 |
|
|
|
10 |
def predict(img):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
|
|
16 |
examples = ['image.jpg']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
interface.queue(api_open=True)
|
18 |
-
|
19 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
|
|
3 |
from fastai.vision.all import PILImage
|
4 |
|
5 |
+
# Load the trained model
|
6 |
learn = load_learner('export.pkl')
|
7 |
|
8 |
+
# Get the labels from the data loaders
|
9 |
labels = learn.dls.vocab
|
10 |
|
11 |
+
# Define the prediction function
|
12 |
def predict(img):
|
13 |
+
img = PILImage.create(img)
|
14 |
+
img = img.resize((512, 512))
|
15 |
+
pred, pred_idx, probs = learn.predict(img)
|
16 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
17 |
|
18 |
+
# Example images for demonstration
|
19 |
examples = ['image.jpg']
|
20 |
+
|
21 |
+
# Create the Gradio interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=gr.components.Image(shape=(512, 512)),
|
25 |
+
outputs=gr.components.Label(num_top_classes=3),
|
26 |
+
)
|
27 |
+
|
28 |
+
# Enable the queue to handle POST requests
|
29 |
interface.queue(api_open=True)
|
30 |
+
|
31 |
+
# Launch the interface
|
32 |
+
interface.launch()
|