Spaces:
Sleeping
Sleeping
File size: 17,866 Bytes
8ea2c88 782e635 22a067b 782e635 22a067b 782e635 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | ---
title: DermaScan AI
emoji: π
colorFrom: red
colorTo: red
sdk: docker
app_port: 7860
tags:
- streamlit
pinned: false
short_description: AI Skin Disease Detection
---
# π₯ DermaScan AI
<div align="center">





**Advanced AI-Powered Dermatology Analysis System**
*Leveraging Deep Learning for Accurate Skin Condition Detection*
[Features](#-features) β’ [Demo](#-demo) β’ [Installation](#-installation) β’ [Usage](#-usage) β’ [Architecture](#-architecture) β’ [Documentation](#-documentation)
</div>
---
## π Table of Contents
- [Overview](#-overview)
- [Features](#-features)
- [Demo](#-demo)
- [Technology Stack](#-technology-stack)
- [Architecture](#-architecture)
- [Installation](#-installation)
- [Usage](#-usage)
- [Model Performance](#-model-performance)
- [Project Structure](#-project-structure)
- [API Documentation](#-api-documentation)
- [Contributing](#-contributing)
- [License](#-license)
- [Acknowledgments](#-acknowledgments)
---
## π¬ Overview
**DermaScan AI** is a production-grade, AI-powered dermatology analysis system that uses deep learning to detect and classify 13 different skin conditions. Built with state-of-the-art computer vision techniques, it provides real-time analysis with 96% AUC-ROC accuracy.
### π― Key Highlights
- **13 Skin Conditions** - Detects 3 cancer types, 4 benign conditions, and 6 skin diseases
- **96% AUC-ROC** - High accuracy validated on medical datasets
- **Real-time Analysis** - Fast inference with EfficientNet-B3 architecture
- **Medical-Grade UI** - Professional dark-mode interface optimized for healthcare
- **India-Optimized** - Location-based hospital finder with emergency contacts
- **Production-Ready** - Modular architecture with FastAPI backend and Streamlit frontend
---
## β¨ Features
### π§ AI-Powered Detection
- **EfficientNet-B3 Architecture** - State-of-the-art CNN for image classification
- **Transfer Learning** - Pre-trained on ImageNet, fine-tuned on medical datasets
- **Test-Time Augmentation (TTA)** - Enhanced prediction accuracy
- **Confidence Scoring** - Transparent AI decision-making
### π Comprehensive Analysis
- **13 Condition Types**
- **Cancer (3)**: Melanoma, Basal Cell Carcinoma, Actinic Keratoses
- **Benign (4)**: Melanocytic Nevi, Benign Keratosis, Dermatofibroma, Vascular Lesions
- **Diseases (6)**: Acne & Rosacea, Eczema, Psoriasis, Fungal Infection, Warts, Vitiligo
- **Differential Diagnosis** - Top alternative conditions with probabilities
- **Severity Classification** - Critical, High, Medium, Low risk levels
- **Care Recommendations** - Personalized advice based on condition
### π₯ Healthcare Integration
- **Hospital Finder** - Google Maps integration for nearby specialists
- **Emergency Contacts** - Quick access to India helplines
- **Location-Based** - State and city-specific recommendations
- **Medical Disclaimer** - Clear guidance on professional consultation
### π¨ Professional UI
- **Dark Mode** - Eye-friendly medical-grade interface
- **Responsive Design** - Works on desktop, tablet, and mobile
- **Interactive Charts** - Plotly visualizations for confidence analysis
- **Real-time Feedback** - Loading states and progress indicators
---
## π¬ Demo
### Upload & Analyze
```
1. Upload a clear, well-lit skin image
2. Select your location (State/City)
3. Click "Analyze Image"
4. Get instant AI-powered diagnosis
```
### Results Dashboard
- **Severity Banner** - Color-coded risk level
- **Confidence Metrics** - AI confidence score and classification
- **Diagnosis Tab** - Detailed condition information
- **Confidence Chart** - Visual probability distribution
- **Care Advice** - Recommended actions and risk factors
- **Hospital Finder** - Embedded Google Maps with nearby specialists
---
## π οΈ Technology Stack
### Backend
- **Python 3.8+** - Core programming language
- **PyTorch 2.0+** - Deep learning framework
- **FastAPI** - High-performance API framework
- **Uvicorn** - ASGI server
- **Pydantic** - Data validation
### Frontend
- **Streamlit** - Interactive web application
- **Plotly** - Data visualization
- **HTML/CSS/JavaScript** - Custom styling
### ML/AI
- **EfficientNet-B3** - CNN architecture
- **torchvision** - Image transformations
- **Albumentations** - Data augmentation
- **scikit-learn** - Metrics and evaluation
### Data
- **HAM10000** - 10,000+ dermatoscopic images
- **DermNet** - Comprehensive dermatology dataset
---
## ποΈ Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Streamlit) β
β ββββββββββββ ββββββββββββ ββββββββββββ βββββββββββ β
β β Header β β Sidebar β β Upload β β Results β β
β ββββββββββββ ββββββββββββ ββββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β HTTP/REST API
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend (FastAPI) β
β ββββββββββββ ββββββββββββ ββββββββββββ βββββββββββ β
β β API β β Model β β Response β β Utils β β
β β Routes β β Inferenceβ β Engine β β β β
β ββββββββββββ ββββββββββββ ββββββββββββ βββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ML Model (PyTorch) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β EfficientNet-B3 (Pre-trained) β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β β β Conv ββ β MBConv ββ β MBConv ββ β Head β β β
β β β Stem β β Blocks β β Blocks β β (FC) β β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### Data Flow
1. **User uploads image** β Frontend (Streamlit)
2. **Image sent to API** β Backend (FastAPI)
3. **Preprocessing** β Resize, normalize, augment
4. **Model inference** β EfficientNet-B3 prediction
5. **Post-processing** β Confidence, severity, recommendations
6. **Response generation** β Care advice, hospital finder
7. **Results display** β Interactive dashboard
---
## π¦ Installation
### Prerequisites
- Python 3.8 or higher
- pip package manager
- 4GB+ RAM recommended
- GPU optional (for training)
### Quick Start
1. **Clone the repository**
```bash
git clone https://github.com/yourusername/dermascan-ai.git
cd dermascan-ai
```
2. **Create virtual environment**
```bash
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
---
## π Usage
### Running the Application
#### 1. Start the Backend API
```bash
# Terminal 1
python -m api.app
# API will be available at http://localhost:8000
# Swagger docs at http://localhost:8000/docs
```
#### 2. Start the Frontend
```bash
# Terminal 2
streamlit run frontend/app.py
# App will open at http://localhost:8501
```
### Using the Application
1. **Upload Image**
- Click "Browse files" or drag & drop
- Supported formats: JPG, JPEG, PNG
- Recommended: Clear, well-lit close-up photos
2. **Select Location**
- Choose your State from sidebar
- Select your City
- Used for hospital recommendations
3. **Analyze**
- Click "π¬ Analyze Image" button
- Wait for AI processing (2-5 seconds)
- View comprehensive results
4. **Review Results**
- **Diagnosis Tab**: Condition details and confidence
- **Confidence Tab**: Visual probability chart
- **Care Advice Tab**: Recommendations and risk factors
- **Hospitals Tab**: Find nearby specialists
---
## π Model Performance
### Metrics (Test Set)
| Metric | Score |
|--------|-------|
| **AUC-ROC** | 96.0% |
| **Accuracy** | 89.2% |
| **Precision** | 87.5% |
| **Recall** | 88.1% |
| **F1-Score** | 87.8% |
### Per-Class Performance
| Condition | Precision | Recall | F1-Score |
|-----------|-----------|--------|----------|
| Melanoma | 92.3% | 89.7% | 91.0% |
| Basal Cell Carcinoma | 88.5% | 91.2% | 89.8% |
| Actinic Keratoses | 85.7% | 87.3% | 86.5% |
| Melanocytic Nevi | 90.1% | 88.9% | 89.5% |
| Benign Keratosis | 86.4% | 85.2% | 85.8% |
| Eczema | 89.7% | 90.5% | 90.1% |
| Psoriasis | 87.2% | 88.8% | 88.0% |
### Training Details
- **Dataset**: HAM10000 + DermNet (10,000+ images)
- **Architecture**: EfficientNet-B3
- **Optimizer**: AdamW with cosine annealing
- **Loss**: Focal Loss (class imbalance handling)
- **Augmentation**: Rotation, flip, color jitter, cutout
- **Training Time**: ~6 hours on NVIDIA RTX 3090
---
## π Project Structure
```
dermascan-ai/
βββ api/ # Backend API
β βββ app.py # FastAPI application
β βββ schemas.py # Pydantic models
β
βββ frontend/ # Streamlit UI
β βββ app.py # Main application
β βββ assets/
β β βββ style.css # Dark mode styling
β β βββ sample_images/ # Sample test images
β βββ components/ # Reusable components
β β βββ header.py # Medical header
β β βββ sidebar.py # Location & info panel
β β βββ result_card.py # Severity banners & metrics
β β βββ confidence_chart.py # Plotly charts
β β βββ care_advice_card.py # Care recommendations
β β βββ hospital_map.py # Google Maps integration
β βββ pages/ # Additional pages (if any)
β
βββ src/ # Core ML code
β βββ inference/ # Prediction
β β βββ predictor.py # Model inference logic
β βββ response/ # Response generation
β βββ response_engine.py # Response builder
β βββ hospital_finder.py # Hospital search logic
β
βββ configs/ # Configuration files
β βββ config.yaml # Training config
β βββ class_config.json # Class mappings
β βββ india_cities.json # Location data
β βββ response_templates.json # Response templates
β
βββ checkpoints/ # Model checkpoints
β βββ best_model.pth # Trained model (96% AUC)
β
βββ notebooks/ # Jupyter notebooks
β βββ 01-data-pipeline.ipynb # Data preprocessing
β βββ 02-training.ipynb # Model training
β
βββ results/ # Training results
β βββ confusion_matrix.png # Confusion matrix
β βββ training_curves.png # Loss/accuracy curves
β βββ per_class_performance.png
β βββ classification_report.txt
β βββ test_metrics.json
β βββ training_history.json
β βββ augmentation_examples.png
β βββ gradcam_*.png # GradCAM visualizations
β
βββ venv/ # Virtual environment (not in git)
β
βββ .gitignore # Git ignore rules
βββ LICENSE # MIT License
βββ README.md # This file
βββ requirements.txt # Python dependencies
```
### π Key Files
| File | Description |
|------|-------------|
| `api/app.py` | FastAPI backend server |
| `frontend/app.py` | Streamlit web interface |
| `src/inference/predictor.py` | Model inference engine |
| `src/response/response_engine.py` | Response generation logic |
| `checkpoints/best_model.pth` | Trained EfficientNet-B3 model |
| `configs/class_config.json` | Disease class mappings |
| `configs/response_templates.json` | Care advice templates |
| `configs/india_cities.json` | Indian states and cities |
### ποΈ Directory Purpose
- **`api/`** - RESTful API backend with FastAPI
- **`frontend/`** - User interface with Streamlit
- **`src/`** - Core ML inference and response logic
- **`configs/`** - Configuration files and templates
- **`checkpoints/`** - Trained model weights
- **`notebooks/`** - Jupyter notebooks for experimentation
- **`results/`** - Training metrics and visualizations
- **`venv/`** - Python virtual environment (excluded from git)
---
## π API Documentation
### Endpoints
#### `POST /predict`
Analyze a skin image and return diagnosis.
**Request:**
```bash
curl -X POST "http://localhost:8000/predict" \
-F "file=@image.jpg" \
-F "city=New Delhi" \
-F "state=Delhi"
```
**Response:**
```json
{
"predicted_class": "Melanoma",
"confidence": 0.92,
"tier": "CANCER",
"severity": "CRITICAL",
"tagline": "Urgent Medical Attention Required",
"action": "Consult an oncologist immediately",
"description": "Melanoma is a serious form of skin cancer...",
"all_probabilities": {
"Melanoma": 0.92,
"Basal Cell Carcinoma": 0.04,
...
},
"differential_diagnosis": [...],
"care_advice": [...],
"risk_factors": [...],
"hospital_type": "Oncologist",
"hospital_search_query": "oncologist near me",
"emergency_numbers": {...},
"inference_time": 2.34
}
```
#### `GET /health`
Check API health status.
**Response:**
```json
{
"status": "healthy",
"model_loaded": true,
"version": "1.0.0"
}
```
### Interactive Documentation
- Swagger UI: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`
---
## π€ Contributing
We welcome contributions! Please follow these steps:
1. **Fork the repository**
2. **Create a feature branch**
```bash
git checkout -b feature/amazing-feature
```
3. **Commit your changes**
```bash
git commit -m "Add amazing feature"
```
4. **Push to the branch**
```bash
git push origin feature/amazing-feature
```
5. **Open a Pull Request**
### Contribution Guidelines
- Follow PEP 8 style guide
- Add unit tests for new features
- Update documentation
- Ensure all tests pass
---
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## π Acknowledgments
### Datasets
- **HAM10000**: Harvard Dataverse - Dermatoscopic Images
- **DermNet**: DermNet New Zealand Trust
### Frameworks & Libraries
- **PyTorch**: Deep learning framework
- **FastAPI**: Modern web framework
- **Streamlit**: Interactive web apps
- **EfficientNet**: Efficient CNN architecture
### Inspiration
- Medical professionals and dermatologists
- Open-source AI/ML community
- Healthcare accessibility initiatives
---
## β οΈ Medical Disclaimer
**IMPORTANT**: DermaScan AI is an educational and screening tool. It is **NOT** a substitute for professional medical diagnosis, treatment, or advice.
- Always consult a qualified dermatologist for proper evaluation
- Do not use this tool for self-diagnosis or treatment decisions
- Seek immediate medical attention for concerning symptoms
- This tool is for research and educational purposes only
---
## π Contact & Support
- **Issues**: [GitHub Issues](https://github.com/yourusername/dermascan-ai/issues)
- **Discussions**: [GitHub Discussions](https://github.com/yourusername/dermascan-ai/discussions)
- **Email**: your.email@example.com
---
## π Star History
If you find this project useful, please consider giving it a β!
---
<div align="center">
**Built with β€οΈ for Healthcare Accessibility**
*DermaScan AI - Empowering Early Detection Through AI*
</div>
|