lyimo commited on
Commit
b6ffc6c
·
verified ·
1 Parent(s): da1f4ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -19
app.py CHANGED
@@ -1,30 +1,20 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
3
  import skimage
4
-
5
 
6
  learn = load_learner('model.pkl')
7
- #from huggingface_hub import from_pretrained_fastai
8
- #learn = from_pretrained_fastai("devdatanalytics/commonbean")
9
 
10
  labels = learn.dls.vocab
 
11
  def predict(img):
12
- img = PILImage.create(img)
13
- pred,pred_idx,probs = learn.predict(img)
14
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
15
 
16
- #title = "Common beans diseases classfier"
17
- #description = "An app for Common beans diseases Classisfication"
18
- #article="<p style='text-align: center'>The app identifies and classifies common beans diseases: Anthracnose and Bean rust.</p>"
19
- # Create the Gradio interface
20
- interface = gr.Interface(
21
- fn=predict,
22
- inputs=gr.Image(),
23
- outputs=gr.Label(num_top_classes=3)
24
- )
25
 
26
- # Enable the queue to handle POST requests
27
- interface.queue(api_open=True)
28
 
29
- # Launch the interface
30
- interface.launch()
 
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('model.pkl')
 
 
7
 
8
  labels = learn.dls.vocab
9
+
10
  def predict(img):
11
+ img = PILImage.create(img)
12
+ img = img.resize((512, 512))
13
+ pred,pred_idx,probs = learn.predict(img)
14
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
15
 
16
+ #examples = ['image.jpg']
 
 
 
 
 
 
 
 
17
 
18
+ #gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
19
+ gr.Interface(fn=predict,inputs=gr.Image(),outputs=gr.Label(num_top_classes=3)).launch().share=True
20