raidAthmaneBenlala/derm-ai
0
DermAI - Web Application
Skin Lesion Segmentation System
A modern web application for AI-powered skin lesion segmentation using Attention U-Net deep learning model.
๐ Quick Start
Prerequisites
- Python 3.8+
- pip (Python package manager)
Installation
- Clone/Navigate to the project:
cd "/home/raid/Desktop/isic2018 skin cancer app"- Activate the virtual environment:
source ~/cv-env/bin/activate- Install dependencies:
pip install -r server/requirements.txt- Add your trained model:
# Copy your trained model to:
models/model.pth- Run the server:
cd server
python main.pyOr with uvicorn:
uvicorn server.main:app --reload --host 0.0.0.0 --port 8000- Open in browser:
http://localhost:8000๐ Project Structure
isic2018-skin-cancer-app/
โโโ client/ # Frontend (HTML/CSS/JS)
โ โโโ index.html # Main HTML page
โ โโโ styles.css # CSS styles (dark medical theme)
โ โโโ app.js # JavaScript (file upload, API calls)
โ
โโโ server/ # Backend (FastAPI)
โ โโโ main.py # FastAPI application & model
โ โโโ requirements.txt # Python dependencies
โ
โโโ models/ # Trained model weights
โ โโโ model.pth # (add your trained model here)
โ
โโโ notebooks/ # Training notebooks
โ โโโ mobileNetUnetAttention.py
โ
โโโ README.md # This file
โโโ README_AI.md # AI/Model documentation๐ฅ๏ธ Features
Frontend
- Modern Medical Theme: Dark mode with purple/pink gradient accents
- Drag & Drop Upload: Easy image upload with drag-and-drop support
- Real-time Results: Instant visualization of segmentation results
- Responsive Design: Works on desktop, tablet, and mobile
- Download Results: Export combined analysis as PNG image
Backend (API)
- FastAPI Framework: High-performance async Python server
- CORS Enabled: Cross-origin requests supported
- Health Check: API status monitoring endpoint
- Image Validation: Supports JPEG, PNG, WebP formats
๐ API Endpoints
Health Check
GET /api/healthResponse:
{
"status": "healthy",
"model_loaded": true,
"device": "cuda"
}Segmentation
POST /api/segment
Content-Type: multipart/form-data
file: <image_file>Response:
{
"success": true,
"mask_base64": "iVBORw0KGgo...",
"overlay_base64": "iVBORw0KGgo...",
"confidence": 85.5,
"lesion_area_percent": 12.3
}๐จ Design System
Color Palette
Typography
- Primary Font: Inter (Google Fonts)
- Monospace Font: JetBrains Mono
- Headings: 700-800 weight
- Body: 400-500 weight
Effects
- Glassmorphism: Blur + transparency on cards
- Gradient Orbs: Animated background blobs
- Smooth Transitions: 250ms ease animations
- Hover States: Lift + glow effects
โจ๏ธ Keyboard Shortcuts
๐ ๏ธ Configuration
Server Configuration (server/main.py)
# Model path
MODEL_PATH = "../models/model.pth"
# Image size (must match training)
IMG_SIZE = 256
# Device (auto-detected)
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')Running on Different Port
uvicorn server.main:app --port 3000Production Mode
uvicorn server.main:app --host 0.0.0.0 --port 8000 --workers 4๐งช Testing
API Test with cURL
# Health check
curl http://localhost:8000/api/health
# Segmentation
curl -X POST http://localhost:8000/api/segment \
-F "file=@test_image.jpg"API Test with Python
import requests
# Health check
response = requests.get("http://localhost:8000/api/health")
print(response.json())
# Segmentation
with open("test_image.jpg", "rb") as f:
response = requests.post(
"http://localhost:8000/api/segment",
files={"file": f}
)
print(response.json())๐ฆ Dependencies
Python (Backend)
fastapi>=0.104.0
uvicorn>=0.24.0
python-multipart>=0.0.6
torch>=2.0.0
torchvision>=0.15.0
opencv-python>=4.8.0
Pillow>=10.0.0
albumentations>=1.3.0
numpy>=1.24.0
pydantic>=2.0.0Frontend
- Vanilla HTML5
- Vanilla CSS3
- Vanilla JavaScript (ES6+)
- Google Fonts (Inter, JetBrains Mono)
๐ Security Notes
- All image processing is done locally (no external API calls)
- Images are processed in memory and not stored
- CORS is enabled for development (restrict in production)
๐ Troubleshooting
Model not found
โ Model file not found at models/model.pthSolution: Add your trained model to the models/ directory.
CUDA out of memory
RuntimeError: CUDA out of memorySolution: Reduce batch size or use CPU:
DEVICE = torch.device('cpu')Port already in use
OSError: [Errno 98] Address already in useSolution: Kill the existing process or use a different port:
lsof -i :8000 # Find process
kill -9 <PID> # Kill itStatic files not serving
Solution: Ensure the client directory exists and contains index.html:
ls -la client/๐ License
This project is for research and educational purposes only. โ ๏ธ Medical Disclaimer: This tool should not be used as a substitute for professional medical advice, diagnosis, or treatment.
๐ฅ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
๐ Support
For issues and questions, please open a GitHub issue.
Version 1.0.0 | Built with FastAPI, PyTorch & โค๏ธ
