--- title: Building Detection API emoji: 🏗️ colorFrom: red colorTo: red sdk: docker app_port: 7860 pinned: true --- # 🏗️ Building Detection API Detect buildings from satellite imagery using Mask R-CNN V5. ## API Endpoints - `GET /` — Health check + model info - `GET /health` — Health check - `POST /detect` — Detect buildings in a polygon area ## Usage ```bash curl -X POST https://your-space.hf.space/detect \ -H "Content-Type: application/json" \ -d '{ "coordinates": [[31.24, 30.04], [31.25, 30.04], [31.25, 30.05], [31.24, 30.05]], "threshold": 0.3 }' ``` ## Environment Variables | Variable | Default | Description | |----------|---------|-------------| | `MODEL_REPO` | `yusef75/building-detection-models` | HF model repository | | `MODEL_VERSION` | `v5` | Model version folder | | `MODEL_FILENAME` | `model_final.pth` | Model file name | | `SCORE_THRESHOLD` | `0.3` | Default detection threshold | --- ## 📋 تقرير جلسة العمل — 27/2/2026 الساعة 1:00 AM ### 1. 🛡️ Live Tile Counter — حدود الرسم الذكية - أضفنا عداد tiles يعمل **أثناء الرسم** في الخريطة مباشرة - يتغير لونه تلقائياً: 🟢 (آمن) → 🟡 (اقترب من الحد) → 🔴 (تجاوز الحد) - لو المستخدم رسم منطقة > **12 tile** → المضلع بيتمسح تلقائياً مع رسالة خطأ واضحة - الحد الأقصى = 12 tile لضمان استقرار pipeline V5.1 ### 2. 🔧 إصلاح SigLIP - **المشكلة:** `AutoProcessor` + `AutoModel` كانوا يرجعوا `None` مع SigLIP على بعض إصدارات transformers - **الحل:** استبدلناهم بـ `SiglipProcessor` + `SiglipModel` المخصصين لـ SigLIP مباشرة - **الملف المعدّل:** `post_processor.py` — دالة `load_siglip()` ### 3. 🚀 تحسين Parallel Processing - **المشكلة:** `Promise.all` كان يوقف كل العمليات لو chunk واحد فشل - **الحل:** استبدلناه بـ `Promise.allSettled` مع `catch` منفصل لكل chunk - النتيجة: فشل chunk واحد لا يوقف باقي الـ chunks ### 4. 🌐 4 HF Spaces بالتوازي (Horizontal Scaling) - أنشأنا 3 Spaces جديدة على نفس الحساب `yusef75`: - `yusef75/building-detection-2` - `yusef75/building-detection-3` - `yusef75/building-detection-4` - كل Space بياخد CPU مستقل من HF = معالجة متوازية حقيقية - عدّلنا `app.js` ليوزّع الـ chunks بـ **Round-Robin** على الـ 4 endpoints ### 5. 📦 GitHub + Vercel Deploy - أنشأنا GitHub repo للـ Backend: `yusef47/building-detection-api` - أنشأنا GitHub repo للـ Frontend: `yusef47/building-detection-website` - ربطنا الـ Frontend repo بـ **Vercel** للنشر التلقائي - كل `git push` على الـ backend يحدّث الـ 4 HF Spaces تلقائياً ### 📊 مقارنة الأداء | السيناريو | الوقت | |-----------|-------| | قبل (1 Space × 12 tiles) | ~800 ثانية ❌ | | بعد (4 Spaces × 3 tiles) | ~200 ثانية ✅ | ### 🗺️ V6 Roadmap (مناقشة) - قرّرنا تطوير V6 باستخدام **RemoteCLIP ViT-L** كـ backbone بدل ResNet-50 - Two-Stage Fine-tuning: عالمي (SpaceNet/INRIA) ← ثم مصر (1.2M مبنى) - إضافة **Qwen2-VL-2B** كـ reviewer يراجع الـ masks ويكتشف المفقود - التفاصيل الكاملة في ملف `V6_ROADMAP.md`