UDAYAN159/DraftClear
DraftClear - AI-Powered CAD Label Resolution System
Overview
DraftClear is an intelligent CAD drawing processing system that automatically resolves label placement conflicts in engineering drawings using advanced AI and machine learning. It transforms cluttered CAD drawings with overlapping text labels into clean, collision-free outputs.
Problem Statement
In dense engineering drawings, text labels frequently collide with or overlap mechanical geometry, creating a "CAPTCHA effect" where labels become unreadable. DraftClear solves this through an agentic AI pipeline.
Key Features
✅ 100% Collision-Free Output - Guarantees zero overlaps ✅ Multi-Format Support - PNG, JPG, BMP, DXF, DWG ✅ AI-Powered Detection - YOLOv10 for precise text detection ✅ Intelligent Reasoning - Ollama-based supervisor for smart decisions ✅ Real-Time Processing - Fast, optimized pipeline ✅ Professional UI - KPMG-inspired, enterprise-grade frontend ✅ PDF Export - Detailed reports and comparison images
Architecture
Core Pipeline (5-Agent Loop)
┌─────────────────────────────────┐
│ 1. Perception Agent (YOLOv10) │ → Detect text labels
├─────────────────────────────────┤
│ 2. Masking Agent │ → Remove overlapping geometry
├─────────────────────────────────┤
│ 3. Spatial Resolution Agent │ → Calculate safe coordinates
├─────────────────────────────────┤
│ 4. Healing Agent (GAN) │ → Repair damaged geometry
├─────────────────────────────────┤
│ 5. Supervisor Agent (Ollama) │ → Validate & decide loop/compile
└─────────────────────────────────┘Technology Stack
Installation
Prerequisites
- Python 3.8+
- pip
- Ollama (optional, for LLM supervisor)
Step 1: Clone Repository
git clone https://github.com/Udayan810/DraftClear.git
cd DraftClearStep 2: Create Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateStep 3: Install Dependencies
pip install -r requirements.txtStep 4: Download YOLOv10 Model (First Run Only)
python -c "from agents.perception import PerceptionAgent; PerceptionAgent()"This will auto-download yolov10n.pt (~5.6 MB) on first run.
Step 5: (Optional) Setup Ollama
# Download Ollama from https://ollama.ai
ollama serve
# In another terminal:
ollama pull mistral # or llama2Quick Start
Run Backend Server
python run.pyThen open your browser: http://localhost:8000
Run with Ollama Support
Terminal 1 - Start Ollama:
ollama serveTerminal 2 - Start Backend:
python run.pyAPI Endpoints
Health Check
GET /api/healthProcess Drawing (Image/CAD)
POST /api/process
Content-Type: multipart/form-data
file: <image or DXF/DWG file>
output_name: "drawing_001"Download Results
GET /api/download/pdf/{output_name}
GET /api/download/image/{output_name}_comparisonAPI Documentation
http://localhost:8000/docsSupported Formats
Input Formats
- Images: PNG, JPG, BMP, GIF, WebP
- CAD: DXF, DWG (basic support)
Output Formats
- Images: PNG (preview, comparison)
- Reports: PDF with metrics and results
Usage Examples
Example 1: Upload Image via Frontend
- Go to
http://localhost:8000 - Drag & drop image or click "Browse Files"
- Select output name
- Click "Process Drawing"
- Download PDF and comparison images
Example 2: Upload DXF File
- Select a DXF file (any valid ezdxf-compatible DXF)
- System automatically converts to image
- Processes through pipeline
- Returns collision-free result
Example 3: API Call
curl -X POST "http://localhost:8000/api/process" \
-F "file=@drawing.png" \
-F "output_name=my_drawing"Performance Metrics
Project Structure
DraftClear/
├── config/
│ ├── __init__.py
│ └── settings.py # Configuration
├── agents/
│ ├── perception.py # YOLOv10 detection
│ ├── masking.py # Text removal
│ ├── spatial_resolution.py # Safe positioning
│ ├── healing.py # Geometry repair
│ └── supervisor.py # Ollama-based QA
├── utils/
│ ├── drawing_state.py # State management
│ └── geometry.py # Shapely utilities
├── frontend/
│ ├── index.html # Web interface
│ ├── styles.css # KPMG-inspired styling
│ └── script.js # Frontend logic
├── api.py # FastAPI backend
├── orchestrator.py # LangGraph orchestration
├── cad_converter.py # DXF/DWG conversion
├── pdf_compiler.py # PDF generation
├── run.py # Server launcher
└── requirements.txt # DependenciesConfiguration
Edit .env file to customize:
# Model Settings
YOLO_MODEL=yolov10n.pt
CONFIDENCE_THRESHOLD=0.5
# Geometry Settings
COLLISION_THRESHOLD=10
PADDING=5
# Ollama Configuration
OLLAMA_URL=http://localhost:11434
OLLAMA_MODEL=mistral
OLLAMA_TIMEOUT=30
# Pipeline Settings
MAX_ITERATIONS=5
LOG_LEVEL=INFOTroubleshooting
Issue: "No text detected"
- Solution: Ensure drawing has visible text labels with sufficient contrast
Issue: "Ollama not available"
- Solution: Start Ollama server or it will use fallback logic (simple collision counting)
Issue: "DXF/DWG conversion failed"
- Solution: Ensure file is valid. Try converting DWG to DXF first using AutoCAD or libre CAD
Issue: "Out of memory"
- Solution: Process smaller drawings or increase available RAM
Performance Optimization
For CPU-Only Systems
- Use
yolov10n.pt(nano model) - default - Reduce image resolution if needed
- Disable Ollama for faster processing
For GPU Systems
- Install PyTorch with CUDA support
- Use
yolov10s.ptor larger for better accuracy
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118Development
Run Tests
pytest tests/Generate Synthetic Training Data
python phase0_synthetic_generator.pyDebug Mode
python run.py --debugContributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature) - Commit changes (
git commit -am 'Add feature') - Push to branch (
git push origin feature) - Open Pull Request
Roadmap
- [ ] GPU acceleration
- [ ] Batch processing
- [ ] Advanced ML-based healing (FFC-GAN)
- [ ] Custom model training UI
- [ ] Real-time collaborative editing
- [ ] Cloud deployment (AWS/Azure)
- [ ] Mobile app
- [ ] REST API authentication
License
MIT License - See LICENSE file for details
Contact & Support
GitHub: Udayan810/DraftClear Issues: GitHub Issues
Acknowledgments
- YOLOv10: Ultralytics for state-of-the-art object detection
- LangGraph: Langchain for agentic orchestration
- ezdxf: DXF file format support
- KPMG: Inspiration for professional design
Made with ❤️ for CAD enthusiasts and engineering automation
