chitang1 commited on
Commit
43ed166
·
verified ·
1 Parent(s): 000c297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio
2
  from fastai.vision.all import *
3
 
4
  # MODELS_PATH = Path('./models')
@@ -15,9 +15,10 @@ LEARN = load_learner('Garbage_Classification.pkl')
15
  LABELS = LEARN.dls.vocab
16
 
17
  def gradio_predict(img):
 
18
  img = PILImage.create(img)
19
  _pred, _pred_idx, probs = LEARN.predict(img)
20
- labels_probs = {LABELS[i]: float(probs[i]) for i, _ in enumerate(LABELS)}
21
  return labels_probs
22
 
23
  # with open('gradio_article.md') as f:
@@ -32,14 +33,21 @@ def gradio_predict(img):
32
  # "theme": "default",
33
  # }
34
 
35
- demo = gradio.Interface(fn=gradio_predict,
36
- inputs=gradio.inputs.Image(shape=(512, 512)),
37
- outputs=gradio.outputs.Label(num_top_classes=5),
38
- **interface_options)
39
 
40
- launch_options = {
41
- "enable_queue": True,
42
- "share": False,
43
- }
44
 
45
- demo.launch(**launch_options)
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from fastai.vision.all import *
3
 
4
  # MODELS_PATH = Path('./models')
 
15
  LABELS = LEARN.dls.vocab
16
 
17
  def gradio_predict(img):
18
+ img = img.resize((512, 512))
19
  img = PILImage.create(img)
20
  _pred, _pred_idx, probs = LEARN.predict(img)
21
+ labels_probs = dict(zip(categories, map(float,probs)))
22
  return labels_probs
23
 
24
  # with open('gradio_article.md') as f:
 
33
  # "theme": "default",
34
  # }
35
 
36
+ image = gr.Image(type="pil", label="Upload an image")
37
+ label = gr.Label()
38
+ examples = ['battery.jpg', 'biological.jpg', 'cardboard.jpg']
 
39
 
40
+ intf = gr.Interface(fn=gradio_predict, inputs=image, outputs=label, examples=examples)
41
+ intf.launch(inline=False)
 
 
42
 
43
+ # demo = gr.Interface(fn=gradio_predict,
44
+ # inputs=gradio.Image(type="pil", label="Upload an image"),
45
+ # outputs=gradio.outputs.Label(num_top_classes=5),
46
+ # **interface_options)
47
+
48
+ # launch_options = {
49
+ # "enable_queue": True,
50
+ # "share": False,
51
+ # }
52
+
53
+ # demo.launch(**launch_options)