Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
# prompt: gradio image 鍒嗙被
|
2 |
import fastai
|
3 |
from fastai.vision import *
|
4 |
-
from fastai.vision.
|
5 |
-
from PIL import Image
|
6 |
import gradio as gr
|
7 |
|
8 |
# Load the model
|
@@ -10,14 +9,13 @@ model = load_learner("model.pkl")
|
|
10 |
|
11 |
# Define an image classification function
|
12 |
def classify_image(image):
|
13 |
-
|
14 |
-
image = Image.create(image).resize((192, 192))
|
15 |
|
16 |
# Make a prediction
|
17 |
-
|
18 |
-
|
19 |
-
# Return the prediction
|
20 |
-
return {
|
21 |
|
22 |
# Create the Gradio interface
|
23 |
image_input = gr.Image()
|
|
|
1 |
# prompt: gradio image 鍒嗙被
|
2 |
import fastai
|
3 |
from fastai.vision import *
|
4 |
+
from fastai.vision.all import load_learner,PILImage
|
|
|
5 |
import gradio as gr
|
6 |
|
7 |
# Load the model
|
|
|
9 |
|
10 |
# Define an image classification function
|
11 |
def classify_image(image):
|
12 |
+
img = PILImage.create(image)
|
|
|
13 |
|
14 |
# Make a prediction
|
15 |
+
pred_class, pred_idx, probs = model.predict(img)
|
16 |
+
|
17 |
+
# Return the prediction as a dictionary
|
18 |
+
return {model.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
|
19 |
|
20 |
# Create the Gradio interface
|
21 |
image_input = gr.Image()
|