dk - edit
This commit is contained in:
@@ -20,8 +20,25 @@ def xyxy_to_xywh(box: dict) -> dict:
|
||||
return {"x": x1, "y": y1, "w": x2 - x1, "h": y2 - y1}
|
||||
|
||||
|
||||
def run(image_path: str) -> dict:
|
||||
def download_image(image_url: str, save_path: str = "image.jpg") -> str:
|
||||
"""원격 이미지 URL을 로컬 파일로 저장하고 경로를 반환한다."""
|
||||
# 이미지 URL 체크
|
||||
if not image_url.startswith("http"):
|
||||
raise ValueError("Invalid image URL")
|
||||
response = requests.get(image_url)
|
||||
response.raise_for_status()
|
||||
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(response.content)
|
||||
return save_path
|
||||
|
||||
|
||||
def run(image_url: str) -> dict:
|
||||
"""이미지 경로를 받아 추론하고 결과 dict를 반환한다."""
|
||||
|
||||
image_path = download_image(image_url)
|
||||
|
||||
|
||||
results = model(image_path)
|
||||
result = results[0]
|
||||
|
||||
@@ -46,23 +63,6 @@ def run(image_path: str) -> dict:
|
||||
return output
|
||||
|
||||
|
||||
def download_image(image_url: str, save_path: str = "image.jpg") -> str:
|
||||
"""원격 이미지 URL을 로컬 파일로 저장하고 경로를 반환한다."""
|
||||
# 이미지 URL 체크
|
||||
if not image_url.startswith("http"):
|
||||
raise ValueError("Invalid image URL")
|
||||
response = requests.get(image_url)
|
||||
response.raise_for_status()
|
||||
|
||||
with open(save_path, "wb") as f:
|
||||
f.write(response.content)
|
||||
return save_path
|
||||
|
||||
|
||||
def main(image_url: str) -> dict:
|
||||
image_path = download_image(image_url)
|
||||
return run(image_path)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 추론 결과를 출력하기 위한 테스트 코드
|
||||
# uv run start.py --image_url "https://acai.ketidev.kr:20443/detect/image/202606/20260619_145116_image.jpg"
|
||||
@@ -70,6 +70,6 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--image_url", type=str, required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
output = main(args.image_url)
|
||||
output = run(args.image_url)
|
||||
|
||||
print(json.dumps(output, indent=2, ensure_ascii=False))
|
||||
|
||||
Reference in New Issue
Block a user