Samanta Das commited on
Commit
7ff4307
·
verified ·
1 Parent(s): 585f09f

Update yolo.py

Browse files
Files changed (1) hide show
  1. yolo.py +5 -4
yolo.py CHANGED
@@ -6,7 +6,7 @@ from datetime import datetime, timedelta
6
  from ultralytics import YOLO
7
  import cv2
8
  import torch
9
- from gradio import Interface, inputs, outputs
10
  from io import BytesIO
11
  import threading
12
 
@@ -103,7 +103,8 @@ class FractureDetector:
103
 
104
  # Return the image in BytesIO format for Gradio
105
  img_byte_arr = BytesIO()
106
- cv2.imwrite(img_byte_arr, img_viz, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
 
107
  img_byte_arr.seek(0) # Go to the beginning of the BytesIO buffer
108
  return img_byte_arr.getvalue() # Return byte content of the image
109
 
@@ -131,8 +132,8 @@ def detect_fractures_in_image(image):
131
  # Define Gradio interface
132
  iface = Interface(
133
  fn=detect_fractures_in_image,
134
- inputs=inputs.Image(type="numpy"),
135
- outputs=outputs.JSON(),
136
  title="Fracture Detection using YOLO",
137
  description="Upload an X-ray image to detect fractures."
138
  )
 
6
  from ultralytics import YOLO
7
  import cv2
8
  import torch
9
+ from gradio import Interface # Use 'gr' as namespace for inputs and outputs
10
  from io import BytesIO
11
  import threading
12
 
 
103
 
104
  # Return the image in BytesIO format for Gradio
105
  img_byte_arr = BytesIO()
106
+ _, img_encoded = cv2.imencode('.jpg', img_viz, [int(cv2.IMWRITE_JPEG_QUALITY), 90])
107
+ img_byte_arr.write(img_encoded)
108
  img_byte_arr.seek(0) # Go to the beginning of the BytesIO buffer
109
  return img_byte_arr.getvalue() # Return byte content of the image
110
 
 
132
  # Define Gradio interface
133
  iface = Interface(
134
  fn=detect_fractures_in_image,
135
+ inputs=gr.Image(type="numpy"), # Use 'gr' to access Image class
136
+ outputs=gr.JSON(), # Use 'gr' to access JSON class
137
  title="Fracture Detection using YOLO",
138
  description="Upload an X-ray image to detect fractures."
139
  )