"""Active Learning dongusu — dusuk guvenli tespitleri otomatik incelemeye gonder.

Bu akis:
  1. Cikarim yap
  2. Dusuk guvenli tespitleri filtrele
  3. Orijinal gorseli veri setine yukle
  4. Insan anotatorler dogrular → model iyilesir

Kullanim:
    python 06_active_learning.py images/*.jpg
"""

import sys
from pathlib import Path

from evren_sdk import EvrenClient

client = EvrenClient(api_key="evren_xxxxx")

DATASET_ID = "019ce417-..."   # hedef veri seti UUID'si
THRESHOLD = 0.5                # bu esik altindaki tespitler incelemeye gider

images = sys.argv[1:] or ["sahne.jpg"]

for img_path in images:
    result = client.predict("kullanici/model", img_path, confidence=0.1)

    belirsiz = result.filter(max_confidence=THRESHOLD)

    if belirsiz.count == 0:
        print(f"  {Path(img_path).name}: tum tespitler yuksek guvenli, skip")
        continue

    resp = client.submit_for_review(DATASET_ID, img_path)

    if resp.get("duplicate"):
        print(f"  {Path(img_path).name}: zaten veri setinde (duplikat)")
    else:
        print(f"  {Path(img_path).name}: yuklendi, {belirsiz.count} belirsiz tespit")
