lyimo commited on
Commit
ae7f96b
1 Parent(s): fcdd24f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
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
- 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
  interface.queue(api_open=True)
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.components.Image(),outputs=gr.components.Label(num_top_classes=3)).launch()
 
 
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()