ruidanwang commited on
Commit
4d59dc6
verified
1 Parent(s): 18c00a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -1,8 +1,7 @@
1
  # prompt: gradio image 鍒嗙被
2
  import fastai
3
  from fastai.vision import *
4
- from fastai.vision.learner import load_learner
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
- # Preprocess the image
14
- image = Image.create(image).resize((192, 192))
15
 
16
  # Make a prediction
17
- prediction = model.predict(image)[0]
18
-
19
- # Return the prediction
20
- return {prediction: 1.0}
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()