delphiclinic commited on
Commit
219dac9
·
verified ·
1 Parent(s): 94dae92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -10,12 +10,34 @@ model = YOLO('best.pt')
10
  #Function for making predictions
11
  def predict (image):
12
  results = model(image)
 
 
13
  for result in results:
14
  im_array = result.plot()
15
- im = Image.fromarray(im_array[..., ::-1]) # RGB PIL image
16
- # im.show() # show image
17
- # im.save('results.jpg')
18
- return im
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
 
21
 
@@ -23,7 +45,7 @@ def predict (image):
23
  platform = gr.Interface( fn = predict,
24
  title ="PTCADx: Computer-Aided Detection of Pneumothorax in Chest X-ray Images",
25
  inputs = "image",
26
- outputs = "image",
27
  description="""
28
  Introducing a revolutionary computer-aided detection tool designed to enhance the efficiency of clinicians in detecting pneumothorax in chest X-ray images.
29
  """,
 
10
  #Function for making predictions
11
  def predict (image):
12
  results = model(image)
13
+ ## list of all the probabilities
14
+ conf = []
15
  for result in results:
16
  im_array = result.plot()
17
+ img = Image.fromarray(im_array[..., ::-1]) # RGB PIL image
18
+ img.show()
19
+ ### Getting the confidence
20
+ box = result.boxes
21
+
22
+ conf.append(box.conf.numpy())
23
+
24
+
25
+ ## sort the confidence from lowest to highest
26
+ if len(conf[0])>1:
27
+ conf_sort = sorted(conf[0]) ## ascending order
28
+ impression = f"Pneumothorax is detected in the image with confidence ranging from {round(conf_sort[0]*100,1)}% to {round(conf_sort[-1]*100,1)}%"
29
+ elif len(conf[0])==1:
30
+ impression = f"Pneumothorax is detected in the image with confidence of {round(conf[0][0]*100,1)}%"
31
+ else:
32
+ impression = "No pneumothorax is detected in the image"
33
+
34
+
35
+
36
+ # print(impression)
37
+
38
+
39
+ return img, impression
40
+
41
 
42
 
43
 
 
45
  platform = gr.Interface( fn = predict,
46
  title ="PTCADx: Computer-Aided Detection of Pneumothorax in Chest X-ray Images",
47
  inputs = "image",
48
+ outputs = ["image", "text"],
49
  description="""
50
  Introducing a revolutionary computer-aided detection tool designed to enhance the efficiency of clinicians in detecting pneumothorax in chest X-ray images.
51
  """,