From fb006f67d7462a39947c839511c0378a629ec417 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 5 Jan 2026 09:41:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=E7=9A=84=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdino/model_wrapper.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gdino/model_wrapper.py b/gdino/model_wrapper.py index c847c1c..37fd02f 100644 --- a/gdino/model_wrapper.py +++ b/gdino/model_wrapper.py @@ -120,13 +120,23 @@ def get_image_url(self, image: Union[str, np.ndarray]): Returns: str: The url of the image """ - if isinstance(image, str): + if isinstance(image, str): + # 如果 image 是文件路径 url = self.client.upload_file(image) else: + # 如果 image 是 numpy 数组,转换为 PNG 格式 with tempfile.NamedTemporaryFile(delete=True, suffix=".png") as tmp_file: - # image is in numpy format, convert to PIL Image + # image 是 numpy 格式,转换为 PIL 图像 image = Image.fromarray(image) image.save(tmp_file, format="PNG") tmp_file_path = tmp_file.name - url = self.client.upload_file(tmp_file_path) + + # 上传文件并打印响应信息 + rsp = self.client.upload_file(tmp_file_path) + print(f"Status code: {rsp.status_code}") + print(f"Response text: {rsp.text}") # 打印返回的响应文本 + assert rsp.status_code == 200 # 确保返回的是200 + + url = rsp.text # 假设返回的是文本,保存响应内容为 URL + return url \ No newline at end of file From 9b14048d0f39bc51382d904e03e9320129b9b610 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 5 Jan 2026 09:45:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=B6=E7=9A=84=E6=97=A5=E5=BF=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdino/model_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdino/model_wrapper.py b/gdino/model_wrapper.py index 37fd02f..6f7a865 100644 --- a/gdino/model_wrapper.py +++ b/gdino/model_wrapper.py @@ -135,7 +135,7 @@ def get_image_url(self, image: Union[str, np.ndarray]): rsp = self.client.upload_file(tmp_file_path) print(f"Status code: {rsp.status_code}") print(f"Response text: {rsp.text}") # 打印返回的响应文本 - assert rsp.status_code == 200 # 确保返回的是200 + assert rsp.status_code == 200, f"上传文件失败,状态码: {rsp.status_code}, 响应内容: {rsp.text}" url = rsp.text # 假设返回的是文本,保存响应内容为 URL