Spaces:
Sleeping
Sleeping
| from pathlib import Path | |
| import json | |
| import sys | |
| import cv2 | |
| from PIL import Image | |
| DEFAULT_LABELS = [ | |
| "melasma skin pigmentation", | |
| "ringworm skin infection ring shape", | |
| "eczema inflamed dry skin", | |
| "acne pimple pustule", | |
| "normal skin", | |
| "birthmark on skin", | |
| "shadow on skin", | |
| "insect bite on skin", | |
| "sunburned skin", | |
| ] | |
| def parse_args(argv): | |
| if len(argv) < 2: | |
| print("Usage: python <script>.py <image_path> [label1] [label2] ...") | |
| return None | |
| image_path = Path(argv[1]) | |
| if not image_path.is_file(): | |
| print(f"Image not found: {image_path}") | |
| return None | |
| labels = argv[2:] if len(argv) > 2 else DEFAULT_LABELS | |
| return image_path, labels | |
| def load_pil_image(image_path): | |
| img = cv2.imread(str(image_path)) | |
| if img is None: | |
| raise ValueError(f"Could not load image: {image_path}") | |
| return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) | |
| def load_bgr_image(image_path): | |
| img = cv2.imread(str(image_path)) | |
| if img is None: | |
| raise ValueError(f"Could not load image: {image_path}") | |
| return img | |
| def print_results(model_name, image_path, results): | |
| print(f"\nModel: {model_name}") | |
| print(f"Image: {image_path}") | |
| print(json.dumps(results, indent=2)) | |
| def exit_with_usage(): | |
| raise SystemExit(1) | |