samschimek commited on
Commit
630ff4d
1 Parent(s): b4732cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -1,20 +1,20 @@
1
- from fastai.vision.all import *
2
  import gradio as gr
 
 
3
 
4
- # Load the trained model
5
  learn = load_learner('ripeorrotten_apple.pkl')
6
 
7
- # Define the prediction categories
8
- categories = ('ripe', 'rotten')
9
-
10
- # Define the prediction function
11
- def classify_image(img):
12
- pred, idx, probs = learn.predict(img)
13
- return dict(zip(categories, map(float, probs)))
14
-
15
- # Define the Gradio interface
16
- image = gr.inputs.Image(shape=(192, 192))
17
- label = gr.outputs.Label()
 
18
 
19
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
20
- intf.launch()
 
 
1
  import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
 
 
5
  learn = load_learner('ripeorrotten_apple.pkl')
6
 
7
+ labels = learn.dls.vocab
8
+ def predict(img):
9
+ img = PILImage.create(img)
10
+ pred,pred_idx,probs = learn.predict(img)
11
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
+
13
+ title = "Ripe or Rotten Apple Classifier"
14
+ description = "A apple quality control classifier (AQCC) trained on web images with fastai."
15
+ #article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
16
+ examples = ['apple-fruit-ripe.jpg']
17
+ interpretation='default'
18
+ enable_queue=True
19
 
20
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()