From f86ee462f52f1b5561299939f7e23a19169f3f4e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:09:06 +0000 Subject: [PATCH 1/2] Initial plan From 8b8d281398622d2ab614280cb7e4c86bbef0ff77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 9 Feb 2026 08:11:18 +0000 Subject: [PATCH 2/2] Fix fire detection backend logic and simplify return handling Co-authored-by: RohanExploit <178623867+RohanExploit@users.noreply.github.com> --- backend/unified_detection_service.py | 37 +++++++++------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/backend/unified_detection_service.py b/backend/unified_detection_service.py index ce9ef16f..bc94ef10 100644 --- a/backend/unified_detection_service.py +++ b/backend/unified_detection_service.py @@ -241,35 +241,22 @@ async def detect_fire(self, image: Image.Image) -> List[Dict]: # Fire detection currently relies on HF API # Future: Add local model support - # We check backend availability but primarily rely on HF for now - # unless a local model is implemented + # We check backend availability but primarily rely on HF for now. + # Treat fire as HF-only: use HF when explicitly selected, or when the + # backend is local but HF fallback is enabled and available. backend = await self._get_detection_backend() - if backend == "huggingface" or backend == "auto": - # Even in auto, if we don't have local fire model, we fallback or use HF if enabled - if await self._check_hf_available(): + if backend == "huggingface" or (backend == "local" and ENABLE_HF_FALLBACK): + if await self._check_hf_available(): from backend.hf_api_service import detect_fire_clip - # Clip returns dict, we need list of dicts - # detect_fire_clip returns {"fire_detected": bool, "confidence": float} or similar dict - # Wait, I need to check detect_fire_clip return type. - # In detection.py it returns {"detections": ...} - # Let's assume it returns a dict-like object or list. - # Actually, most clip functions return dict. - result = await detect_fire_clip(image) - if isinstance(result, list): - return result - if isinstance(result, dict) and "detections" in result: - return result["detections"] - if isinstance(result, dict): - # Wrap in list if it's a single detection dict - return [result] - return [] - - # If we reached here, no suitable backend found + # detect_fire_clip already returns List[Dict] of detections + return await detect_fire_clip(image) + + # If we reached here, no suitable backend found or HF is unavailable if backend == "local": - # Placeholder for local fire detection - logger.warning("Local fire detection not yet implemented") - return [] + # Placeholder for local fire detection + logger.warning("Local fire detection not yet implemented or HF fallback unavailable") + return [] logger.error("No detection backend available for fire detection") # Don't raise exception to avoid failing detect_all, just return empty