Spaces:
Sleeping
Sleeping
| 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> | |