Ekins Kuuzie commited on
Commit
ad37ea0
·
verified ·
1 Parent(s): 59fb740

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -32
app.py CHANGED
@@ -1,10 +1,5 @@
1
  ##importing the libraries
2
-
3
- import torch
4
- import cv2
5
- import os
6
- import numpy as np
7
- import pandas as pd
8
  import gradio as gr
9
  from ultralytics import YOLO
10
 
@@ -12,36 +7,20 @@ from ultralytics import YOLO
12
  # Load your trained model
13
  model = YOLO('best.pt')
14
 
15
- ### Preprocess the new image
16
-
17
- def predict_image(test_image):
18
- # save images
19
- model.predict(test_image, save=True, conf=0.1, batch=2, show=True)
20
-
21
- path = "runs/detect"
22
-
23
- detection = (os.listdir(path))
24
-
25
- def extract_digits(x):
26
- digits = ''.join(filter(str.isdigit, x))
27
- return int(digits) if digits else float('inf') #Use float('inf') as a default value
28
-
29
- sorted_ = sorted(detection, key=extract_digits)
30
-
31
- if len(sorted_)>1:
32
- latest_detection = sorted_[-2] # getting the latest predictions
33
- else:
34
- latest_detection = sorted_[0]
35
-
36
- detection_path = os.path.join(path, latest_detection)
37
-
38
- pred = cv2.imread(os.path.join(detection_path, test_image))
39
- return pred
40
 
41
 
42
 
43
 
44
- platform = gr.Interface( fn = predict_image,
45
  title ="PTCADx: Computer-Aided Detection of Pneumothorax in Chest X-ray Images",
46
  inputs = "image",
47
  outputs = "image",
 
1
  ##importing the libraries
2
+ from PIL import Image
 
 
 
 
 
3
  import gradio as gr
4
  from ultralytics import YOLO
5
 
 
7
  # Load your trained model
8
  model = YOLO('best.pt')
9
 
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
 
22
 
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",