nolenfelten commited on
Commit
4e6ec35
·
verified ·
1 Parent(s): 99f0f19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -59,12 +59,12 @@ def encode_image(image):
59
  image.save(buffered, format="PNG")
60
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
61
 
62
-
63
  def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
64
  '''
65
  Send the image to Roboflow API for inference.
66
  Returns JSON and image with bounding boxes drawn on to it.
67
  '''
 
68
  json_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=json"
69
  image_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=image&labels={str(labels).lower()}&stroke={stroke_width}"
70
 
@@ -74,12 +74,15 @@ def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
74
  json_request = requests.post(json_url, data=encoded_image, headers=headers)
75
  image_request = requests.post(image_url, data=encoded_image, headers=headers)
76
 
 
 
 
77
  if json_request.status_code == 200:
78
  json_response = json_request.json()
79
  else:
80
  json_response = {"error": "Failed to get JSON response"}
81
 
82
- if image_request.status_code == 200:
83
  image_response = Image.open(io.BytesIO(image_request.content))
84
  else:
85
  image_response = None
@@ -88,6 +91,8 @@ def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
88
  "json": json_response,
89
  "image": image_response
90
  }
 
 
91
  # Image Splitting and Merging Functionality
92
  def split_image(image, tile_size=640, overlap=160):
93
  img_width, img_height = image.size
 
59
  image.save(buffered, format="PNG")
60
  return base64.b64encode(buffered.getvalue()).decode("utf-8")
61
 
 
62
  def roboflow(image, confidence, overlap, stroke_width=1, labels=False):
63
  '''
64
  Send the image to Roboflow API for inference.
65
  Returns JSON and image with bounding boxes drawn on to it.
66
  '''
67
+
68
  json_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=json"
69
  image_url = f"https://detect.roboflow.com/sku-110k/2?api_key=gHiUgOSq9GqTnRy5mErk&confidence={confidence}&overlap={overlap}&format=image&labels={str(labels).lower()}&stroke={stroke_width}"
70
 
 
74
  json_request = requests.post(json_url, data=encoded_image, headers=headers)
75
  image_request = requests.post(image_url, data=encoded_image, headers=headers)
76
 
77
+ print("JSON Response Headers:", json_request.headers)
78
+ print("Image Response Headers:", image_request.headers)
79
+
80
  if json_request.status_code == 200:
81
  json_response = json_request.json()
82
  else:
83
  json_response = {"error": "Failed to get JSON response"}
84
 
85
+ if image_request.status_code == 200 and 'image' in image_request.headers.get('Content-Type', ''):
86
  image_response = Image.open(io.BytesIO(image_request.content))
87
  else:
88
  image_response = None
 
91
  "json": json_response,
92
  "image": image_response
93
  }
94
+
95
+
96
  # Image Splitting and Merging Functionality
97
  def split_image(image, tile_size=640, overlap=160):
98
  img_width, img_height = image.size