Spaces:
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
Advanced AI-Powered Dermatology Analysis System
Leveraging Deep Learning for Accurate Skin Condition Detection
Features β’ Demo β’ Installation β’ Usage β’ Architecture β’ Documentation
π Table of Contents
- Overview
- Features
- Demo
- Technology Stack
- Architecture
- Installation
- Usage
- Model Performance
- Project Structure
- API Documentation
- Contributing
- License
- 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
- User uploads image β Frontend (Streamlit)
- Image sent to API β Backend (FastAPI)
- Preprocessing β Resize, normalize, augment
- Model inference β EfficientNet-B3 prediction
- Post-processing β Confidence, severity, recommendations
- Response generation β Care advice, hospital finder
- Results display β Interactive dashboard
π¦ Installation
Prerequisites
- Python 3.8 or higher
- pip package manager
- 4GB+ RAM recommended
- GPU optional (for training)
Quick Start
- Clone the repository
git clone https://github.com/yourusername/dermascan-ai.git
cd dermascan-ai
- Create virtual environment
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
π Usage
Running the Application
1. Start the Backend API
# 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
# Terminal 2
streamlit run frontend/app.py
# App will open at http://localhost:8501
Using the Application
Upload Image
- Click "Browse files" or drag & drop
- Supported formats: JPG, JPEG, PNG
- Recommended: Clear, well-lit close-up photos
Select Location
- Choose your State from sidebar
- Select your City
- Used for hospital recommendations
Analyze
- Click "π¬ Analyze Image" button
- Wait for AI processing (2-5 seconds)
- View comprehensive results
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 FastAPIfrontend/- User interface with Streamlitsrc/- Core ML inference and response logicconfigs/- Configuration files and templatescheckpoints/- Trained model weightsnotebooks/- Jupyter notebooks for experimentationresults/- Training metrics and visualizationsvenv/- Python virtual environment (excluded from git)
π API Documentation
Endpoints
POST /predict
Analyze a skin image and return diagnosis.
Request:
curl -X POST "http://localhost:8000/predict" \
-F "file=@image.jpg" \
-F "city=New Delhi" \
-F "state=Delhi"
Response:
{
"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:
{
"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:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature - Commit your changes
git commit -m "Add amazing feature" - Push to the branch
git push origin feature/amazing-feature - 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 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
- Discussions: GitHub Discussions
- Email: your.email@example.com
π Star History
If you find this project useful, please consider giving it a β!
Built with β€οΈ for Healthcare Accessibility
DermaScan AI - Empowering Early Detection Through AI