PinChunPai commited on
Commit
d20f01d
1 Parent(s): 2dcbbe6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -38,15 +38,15 @@ def classifier_app(image):
38
  top1 = round( prediction[0][top_indices[0][0]].item(), 4)
39
  top2 = round( prediction[0][top_indices[0][1]].item(), 4)
40
  top3 = round( prediction[0][top_indices[0][2]].item(), 4)
41
- others = round(1.0 - top1 - top2-top3, 4)
42
 
43
  len_1 = len(id2label[top_indices[0][0]])
44
  len_2 = len(id2label[top_indices[0][1]])
45
- len_3 = len(id2label[top_indices[0][2]])
46
- max_length = max(len_1, len_2, len_3, len('Others'))
47
 
48
- labels = [f'{id2label[top_indices[0][0]]}'.ljust(max_length), f'{id2label[top_indices[0][1]]}'.ljust(max_length), f'{id2label[top_indices[0][2]]}'.ljust(max_length), f'Others'.ljust(max_length)]
49
- preds = [top1, top2,top3, others]
50
  result = {label : float(pred) for label, pred in zip(labels, preds)}
51
 
52
  return result
@@ -56,6 +56,7 @@ interface = gr.Interface(
56
  fn=classifier_app,
57
  inputs="image",
58
  examples = ['cat_1.jpg','cat_2.jpg','cat_3.jpg'],
59
- outputs="label"
 
60
  )
61
  interface.launch()
 
38
  top1 = round( prediction[0][top_indices[0][0]].item(), 4)
39
  top2 = round( prediction[0][top_indices[0][1]].item(), 4)
40
  top3 = round( prediction[0][top_indices[0][2]].item(), 4)
41
+ others = round(1.0 - top1 - top2, 4)
42
 
43
  len_1 = len(id2label[top_indices[0][0]])
44
  len_2 = len(id2label[top_indices[0][1]])
45
+ # len_3 = len(id2label[top_indices[0][2]])
46
+ max_length = max(len_1, len_2, len('Others'))
47
 
48
+ labels = [f'{id2label[top_indices[0][0]]}'.ljust(max_length), f'{id2label[top_indices[0][1]]}'.ljust(max_length), f'Others'.ljust(max_length)]
49
+ preds = [top1, top2, others]
50
  result = {label : float(pred) for label, pred in zip(labels, preds)}
51
 
52
  return result
 
56
  fn=classifier_app,
57
  inputs="image",
58
  examples = ['cat_1.jpg','cat_2.jpg','cat_3.jpg'],
59
+ outputs="label",
60
+ share=True
61
  )
62
  interface.launch()