shamimjony1000 commited on
Commit
0e01414
·
1 Parent(s): 84e0d1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -16,19 +16,32 @@ model = YOLO('best.pt')
16
  path = [['Cyst.jpg'], ['Stone.jpg'],['Normal.jpg']]
17
 
18
 
19
- def show_preds_image(image_path):
20
  image = cv2.imread(image_path)
21
- outputs = model.predict(source=image_path)
22
- results = outputs[0].cpu().numpy()
23
- for i, det in enumerate(results.boxes.xyxy):
 
 
 
 
 
 
 
 
 
 
 
24
  cv2.rectangle(
25
  image,
26
- (int(det[0]), int(det[1])),
27
- (int(det[2]), int(det[3])),
28
  color=(0, 0, 255),
29
  thickness=2,
30
  lineType=cv2.LINE_AA
31
  )
 
 
32
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
33
 
34
  inputs_image = [
@@ -38,7 +51,7 @@ outputs_image = [
38
  gr.components.Image(type="numpy", label="Output Image"),
39
  ]
40
  interface_image = gr.Interface(
41
- fn=show_preds_image,
42
  inputs=inputs_image,
43
  outputs=outputs_image,
44
  title="Kidney Stone and Cyst detection",
 
16
  path = [['Cyst.jpg'], ['Stone.jpg'],['Normal.jpg']]
17
 
18
 
19
+ def detect_objects_on_image(image_path):
20
  image = cv2.imread(image_path)
21
+ model = YOLO("best.pt")
22
+ results = model.predict(image_path)
23
+ result = results[0]
24
+ output = []
25
+ for box in result.boxes:
26
+ x1, y1, x2, y2 = [
27
+ round(x) for x in box.xyxy[0].tolist()
28
+
29
+ ]
30
+ class_id = box.cls[0].item()
31
+ prob = round(box.conf[0].item(), 2)
32
+ output.append([
33
+ x1, y1, x2, y2, result.names[class_id], prob
34
+ ])
35
  cv2.rectangle(
36
  image,
37
+ (x1, y1),
38
+ (x2, y2),
39
  color=(0, 0, 255),
40
  thickness=2,
41
  lineType=cv2.LINE_AA
42
  )
43
+
44
+ cv2.putText(image,result.names[class_id], (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (36,255,12), 2)
45
  return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
46
 
47
  inputs_image = [
 
51
  gr.components.Image(type="numpy", label="Output Image"),
52
  ]
53
  interface_image = gr.Interface(
54
+ fn=detect_objects_on_image,
55
  inputs=inputs_image,
56
  outputs=outputs_image,
57
  title="Kidney Stone and Cyst detection",