sabaridsnfuji commited on
Commit
e8bbcbb
1 Parent(s): a859642

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -36,7 +36,7 @@ label_to_class_text = {0: 'range',
36
  def predict_image(image):
37
  # Convert PIL Image to numpy array (OpenCV uses numpy arrays)
38
  image = np.array(image)
39
-
40
  # Resize, preprocess, and reshape the input image
41
  img_size = 960
42
  resized_image = cv2.resize(image, (img_size, img_size)) / 255.0
@@ -64,9 +64,9 @@ def predict_image(image):
64
  ])
65
 
66
  if prob > 0.2:
67
- cv2.rectangle(image, (x1, y1), (x2, y2), (255, 255, 0), 2)
68
  label_text = f"{classes} {round(prob, 2)}"
69
- cv2.putText(image, label_text, (x1, y1), 0, 0.5, (0, 255, 0), 2)
70
 
71
  # Store prediction info in a JSON-compatible format
72
  predictions.append({
@@ -81,7 +81,7 @@ def predict_image(image):
81
  })
82
 
83
  # Convert the processed image back to PIL Image for Gradio
84
- pil_image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
85
 
86
  return pil_image, json.dumps(predictions, indent=4)
87
 
 
36
  def predict_image(image):
37
  # Convert PIL Image to numpy array (OpenCV uses numpy arrays)
38
  image = np.array(image)
39
+ temp_image =image
40
  # Resize, preprocess, and reshape the input image
41
  img_size = 960
42
  resized_image = cv2.resize(image, (img_size, img_size)) / 255.0
 
64
  ])
65
 
66
  if prob > 0.2:
67
+ cv2.rectangle(temp_image, (x1, y1), (x2, y2), (255, 255, 0), 2)
68
  label_text = f"{classes} {round(prob, 2)}"
69
+ cv2.putText(temp_image, label_text, (x1, y1), 0, 0.5, (0, 255, 0), 2)
70
 
71
  # Store prediction info in a JSON-compatible format
72
  predictions.append({
 
81
  })
82
 
83
  # Convert the processed image back to PIL Image for Gradio
84
+ pil_image = Image.fromarray(cv2.cvtColor(temp_image, cv2.COLOR_BGR2RGB))
85
 
86
  return pil_image, json.dumps(predictions, indent=4)
87