🎯 Intelligent Diagnostic Agent for Early Detection of Human Melanoma
An AI-powered web application for melanoma detection using a hybrid CNN-Transformer model with explainable AI (Grad-CAM) heatmaps.
Version: 1.0 | Status: Production Ready | License: MIT
📋 Table of Contents
✨ Features
✅ Real-time Melanoma Prediction — Binary classification (Benign/Malignant)
✅ Explainable AI — Grad-CAM heatmaps highlight suspicious regions
✅ Image Verification — Rejects non-dermoscopic images
✅ User Authentication — JWT-based role-based access control
✅ Dermatologist Dashboard — Review predictions & provide feedback
✅ Feedback Analytics — Track model agreement rates
✅ Corrective Fine-tuning — Auto-retrain model from expert feedback
✅ Admin Panel — Manage users & platform settings
✅ Cloud Storage — Cloudinary integration for image hosting
✅ RESTful API — FastAPI with interactive Swagger docs
🎬 Demo
Frontend UI:
📸 Drag & drop image upload
🎨 Visual heatmap overlay
📊 Confidence scores & metrics
⚡ Quick Start (5 Minutes)
Prerequisites
1 ✓ Python 3.10 +
2 ✓ Node.js 18 +
3 ✓ Git
1️⃣ Clone Repository
1 git clone https://github.com/yourusername/melanoma-diagnostic-agent.git
2 cd melanoma-diagnostic-agent
2️⃣ Setup Backend (Terminal 1)
1 # Activate virtual environment
2 python -m venv project-env
3 project-env \ Scripts \ activate # Windows
4 source project-env/bin/activate # Linux/Mac
5
6 # Install dependencies
7 cd project-api
8 pip install -r requirements.txt
9
10 # Ensure model exists
11 # Copy melanoma_model.pth to project-api/models/
12
13 # Start backend
14 uvicorn main:app --reload --port 8000
3️⃣ Setup Frontend (Terminal 2)
1 cd project-spa
2 npm install
3 npm run dev
4️⃣ Test It
Open http://localhost:5173 in browser
Register as Patient
Upload a dermoscopic image
Boom! 💥 See prediction + heatmap
🖥️ System Requirements
Minimum Hardware
Component Requirement CPU 4 cores (i5 or equivalent) RAM 8 GB (16 GB recommended) GPU Optional (NVIDIA CUDA for speed) Storage 20 GB free Browser Chrome, Firefox, Edge, Safari
Software
Tool Version Python 3.10+ Node.js 18+ Docker Latest (optional)
📦 Detailed Setup
Backend Setup
Step 1: Create Python Environment
1 # Windows
2 python -m venv project-env
3 project-env \ Scripts \ activate
4
5 # Linux/Mac
6 python3 -m venv project-env
7 source project-env/bin/activate
Verify activation: You should see (project-env) prefix in terminal.
Step 2: Install Python Dependencies
1 cd project-api
2 pip install -r requirements.txt
Expected packages:
fastapi — Web framework
torch — Deep learning (PyTorch)
torchvision — Image processing
sqlalchemy — Database ORM
pydantic — Data validation
cloudinary — Cloud storage
Step 3: Download Pre-trained Model
1 # Download from HuggingFace
2 # https://huggingface.co/charlykso/melanoma-classifier
3 # Or copy trained model:
4 cp .. /path/to/melanoma_model.pth ./models/
File location (critical): project-api/models/melanoma_model.pth
Step 4: Configure Environment Variables
1 # Create .env file in project-api/
2 CLOUDINARY_API_KEY = your_key
3 CLOUDINARY_API_SECRET = your_secret
4 DATABASE_URL = postgresql://user:password@localhost/melanoma
5 JWT_SECRET = your-secret-key
Step 5: Initialize Database (if using PostgreSQL)
Step 6: Start Backend Server
uvicorn main:app --reload --port 8000
Success Indicators:
INFO: Uvicorn running on http://127.0.0.1:8000
INFO: Application startup complete
Check API health:
1 curl http://localhost:8000/health
2 # Response: {"status": "healthy"}
Frontend Setup
Step 1: Install Node Dependencies
1 cd project-spa
2 npm install
3 # or
4 yarn install
Packages installed:
react — UI framework
typescript — Type safety
axios — HTTP client
tailwindcss — Styling
vite — Build tool
Step 2: Configure API Endpoint (Optional)
1 # Create .env in project-spa/
2 VITE_API_URL = http://localhost:8000
Default: http://localhost:8000
Step 3: Start Development Server
1 npm run dev
2 # or
3 yarn dev
Success Indicators:
Local: http://localhost:5173/
press h to show help
Step 4: Open in Browser
🎮 Usage
1. Register Account
Click "Register"
Enter email & password
Select role: Patient (or Dermatologist if available)
Click "Sign Up"
2. Upload Image
On dashboard, click "Upload Image"
Drag & drop a dermoscopic skin lesion image (JPG/PNG)
Or click to browse files
3. Get Prediction
System verifies it's dermoscopic
Runs melanoma classifier
Generates Grad-CAM heatmap
Wait 3-5 seconds ⏳
4. View Results
Prediction: Benign / Malignant
Confidence: 0-100%
Heatmap: Red regions = model focus areas
History: All predictions saved
5. Dermatologist Review (if available)
Log in as Dermatologist
Review assigned cases
Submit feedback (ground truth diagnosis)
Track agreement rates
📁 Project Structure
melanoma-diagnostic-agent/
│
├── project-api/ # Backend (FastAPI + PyTorch)
│ ├── main.py # Entry point
│ ├── requirements.txt # Python dependencies
│ ├── app/
│ │ ├── config.py # Settings
│ │ ├── routers/ # API endpoints
│ │ ├── models/ # ML models code
│ │ ├── services/ # Business logic
│ │ ├── database/ # Database setup
│ │ └── schemas/ # Request/response schemas
│ ├── models/ # Model weights
│ │ └── melanoma_model.pth # Pre-trained model (REQUIRED)
│ └── static/ # Generated heatmaps
│
├── project-spa/ # Frontend (React + TypeScript)
│ ├── package.json # npm dependencies
│ ├── src/
│ │ ├── main.tsx # Entry point
│ │ ├── App.tsx # Main component
│ │ ├── pages/ # Page components
│ │ ├── components/ # Reusable components
│ │ ├── services/ # API client
│ │ └── styles/ # CSS/Tailwind
│ └── vite.config.ts # Vite configuration
│
├── project-env/ # Python virtual environment
│ ├── Scripts/ # Executables (Windows)
│ └── lib/site-packages/ # Installed packages
│
├── Software_Documentation.md # Full documentation
└── README.md # This file
🔌 API Documentation
Interactive Docs
Key Endpoints
Authentication
1 POST /auth/register # Create account
2 POST /auth/login # Login
3 GET /auth/me # Get profile
Predictions
1 POST /predict # Upload image → get prediction
2 GET /predictions # Prediction history
3 GET /predictions/ { id } # Single prediction
Dermatologist
1 GET /dermatologist/stats # Dashboard stats
2 GET /dermatologist/predictions # Assigned cases
3 POST /predictions/ { id } /feedback # Submit diagnosis
Admin
1 GET /admin/stats # Platform statistics
2 GET /admin/users # User management
🐛 Troubleshooting
Backend Issues
Problem Solution ModuleNotFoundError: No module named 'torch'Run pip install -r requirements.txt again, ensure virtual env activated Port 8000 already in useUse different port: uvicorn main:app --port 8001 Model not found errorDownload melanoma_model.pth and place in models/ directory Database connection errorEnsure PostgreSQL running: psql -U postgres CORS error in browserCheck backend is running on correct port (8000)
Frontend Issues
Problem Solution npm ERR! Cannot find moduleDelete node_modules/ and package-lock.json, then npm install Port 3000/5173 already in useKill process: lsof -ti:5173 | xargs kill -9 (Linux/Mac) or use different port Blank/white pageCheck browser console (F12), ensure backend URL in .env correct Image upload not workingVerify backend running & model loaded at http://localhost:8000/docs
General Issues
Problem Solution Connection refusedEnsure both backend & frontend are running in separate terminals Slow inference (>10s)Model running on CPU. Install GPU drivers for CUDA acceleration Database errorsIf using SQLite (default), ensure data/ folder exists with permissions
✅ Verification Checklist
After setup, verify everything works:
Backend Check
1 # Health check
2 curl http://localhost:8000/health
3
4 # Should return:
5 # {"status": "healthy", "model_loaded": true}
Frontend Check
✅ Page loads without white/blank screen
✅ No errors in browser console (F12 → Console tab)
✅ Can see login/register forms
✅ Images upload without errors
Full System Test
Register account
Upload test dermoscopic image
See prediction result
View Grad-CAM heatmap
Result appears in prediction history
🚀 Next Steps
After successful setup:
Development
1 # Run with auto-reload
2 uvicorn main:app --reload
3
4 # Run tests
5 pytest project-api/tests/
6
7 # Format code
8 black project-api/
Production Deployment
1 # Using Docker
2 docker-compose up --build
3
4 # Or manual:
5 # - Set DEBUG=False in .env
6 # - Configure ALLOWED_HOSTS
7 # - Setup proper database (PostgreSQL recommended)
8 # - Use production server (Gunicorn)
Model Training
1 cd project-api
2 python train.py --epochs 50 --batch-size 32
📚 Documentation
Full Setup Guide: See Software_Documentation.md
API Reference: http://localhost:8000/docs (after startup)
Model Details: See project-api/README.md
Frontend Guide: See project-spa/README.md
🤝 Contributing
Contributions welcome! Please:
Fork repository
Create feature branch: git checkout -b feature/amazing-feature
Commit changes: git commit -m 'Add amazing feature'
Push to branch: git push origin feature/amazing-feature
Open Pull Request
📄 License
This project is licensed under the MIT License. See LICENSE file for details.
👨💼 Author
Charles — MSc Thesis Project
Intelligent Diagnostic Agent for Early Detection of Human Melanoma
🆘 Support
Issues? Check:
Troubleshooting section above
API docs: http://localhost:8000/docs
Full docs: Software_Documentation.md
🎓 Citation
If you use this project in research, please cite:
1 @thesis{melanoma2026,
2 author = {Charles},
3 title = {Intelligent Diagnostic Agent for Early Detection of Human Melanoma},
4 school = {University Name},
5 year = {2026}
6 }
📊 Project Status
Component Status Backend API ✅ Production Ready Frontend UI ✅ Production Ready Model Training ✅ Completed (ISIC 2018) Deployment ✅ Docker Support Tests 🔄 In Progress Documentation ✅ Complete
Last Updated: April 2026 | Version: 1.0