# detector_yolo.py import os, glob from ultralytics import YOLO # โหลดโมเดล YOLO ที่เทรนเอง yolo_model = YOLO("runs/detect/leukemia-yolo-model/weights/best.pt") def detect_cells_yolo(image_path, output_dir='static/marked/predict'): # สร้างโฟลเดอร์ถ้ายังไม่มี os.makedirs(output_dir, exist_ok=True) # ตรวจจับและบันทึกภาพ yolo_model.predict(source=image_path, save=True, project='static/marked', name='predict', exist_ok=True) # หาภาพล่าสุดที่เพิ่งสร้าง list_of_files = glob.glob(os.path.join(output_dir, '*.jpg')) if not list_of_files: return None latest_file = max(list_of_files, key=os.path.getctime) return os.path.relpath(latest_file, 'static')