import os import base64 from pathlib import Path def generate_combined_report(results, out_dir): """ results is a list of dicts, each containing: - 'before_path': Path or None - 'after_path': Path or None - 'status': 'INTACT' | 'DAMAGED' | 'MISSING' | 'ADDED' - 'cls_score': float - 'patch_score': float - 'geo_inliers': int - 'confidence': str - 'stage_used': int - 'damage_description': str - 'target_phrases_list': list of str - 'masked_after_path': Path or None """ out = Path(out_dir) out.mkdir(parents=True, exist_ok=True) def b64img(path): if not path or not os.path.exists(path): return "" try: p = Path(path) data = base64.b64encode(p.read_bytes()).decode() ext = p.suffix.lstrip(".") or "jpeg" return f"data:image/{ext};base64,{data}" except Exception as e: print(f"Error encoding image {path}: {e}") return "" cards = "" for r in results: status = r['status'] # Determine styling based on status if status == 'INTACT': color = "#10b981" # Emerald bg_color = "rgba(16, 185, 129, 0.05)" border_c = "rgba(16, 185, 129, 0.2)" icon = "✅" label = "INTACT / سليم" elif status == 'DAMAGED': color = "#f59e0b" # Amber bg_color = "rgba(245, 158, 11, 0.05)" border_c = "rgba(245, 158, 11, 0.25)" icon = "⚠️" label = "DAMAGED / تالف" elif status == 'MISSING': color = "#ef4444" # Red bg_color = "rgba(239, 68, 68, 0.05)" border_c = "rgba(239, 68, 68, 0.2)" icon = "❌" label = "MISSING / مفقود" else: # ADDED color = "#3b82f6" # Blue bg_color = "rgba(59, 130, 246, 0.05)" border_c = "rgba(59, 130, 246, 0.25)" icon = "➕" label = "ADDED / مضاف" before_html = "" if r['before_path']: before_src = b64img(r['before_path']) before_name = Path(r['before_path']).name before_html = f"""
{r['damage_description']}
✨ AI analysis confirms this item is intact. No major damage or negative changes were detected. / يؤكد تحليل الذكاء الاصطناعي أن هذا العنصر سليم، ولم يتم رصد أي تلفيات أو تغييرات سلبية.
🔍 This item from the before inventory could not be matched with any item in the after inventory. It may have been moved, stolen, or removed. / لم يتم العثور على مطابقة لهذا العنصر في صور البعد، قد يكون تم نقله، سرقته أو إزالته.
➕ New item added in the after inventory that was not present in the before inventory. / تم رصد عنصر جديد مضاف في صور البعد لم يكن موجوداً في صور القبل.
AI Matching & Inspection System · نظام المطابقة والفحص الذكي بالذكاء الاصطناعي (DINOv2 + Grounded-SAM + MLLM)