CoolFace
Apppublic

raidAthmaneBenlala/derm-ai

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

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

  1. 1.Clone/Navigate to the project:
bash
   cd "/home/raid/Desktop/isic2018 skin cancer app"
  1. 1.Activate the virtual environment:
bash
   source ~/cv-env/bin/activate
  1. 1.Install dependencies:
bash
   pip install -r server/requirements.txt
  1. 1.Add your trained model:
bash
   # Copy your trained model to:
   models/model.pth
  1. 1.Run the server:
bash
   cd server
   python main.py

Or with uvicorn:

bash
   uvicorn server.main:app --reload --host 0.0.0.0 --port 8000
  1. 1.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

http
GET /api/health

Response:

json
{
  "status": "healthy",
  "model_loaded": true,
  "device": "cuda"
}

Segmentation

http
POST /api/segment
Content-Type: multipart/form-data

file: <image_file>

Response:

json
{
  "success": true,
  "mask_base64": "iVBORw0KGgo...",
  "overlay_base64": "iVBORw0KGgo...",
  "confidence": 85.5,
  "lesion_area_percent": 12.3
}

๐ŸŽจ Design System

Color Palette

ColorHSLUsage
Primary Purplehsl(250, 89%, 65%)Buttons, accents
Accent Pinkhsl(330, 81%, 60%)Highlights, gradients
Success Greenhsl(142, 71%, 45%)Positive indicators
Background Darkhsl(240, 20%, 4%)Main background

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

ShortcutAction
Ctrl/Cmd + OOpen file dialog
Ctrl/Cmd + SDownload results
EscapeReset analysis

๐Ÿ› ๏ธ Configuration

Server Configuration (server/main.py)

python
# 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

bash
uvicorn server.main:app --port 3000

Production Mode

bash
uvicorn server.main:app --host 0.0.0.0 --port 8000 --workers 4

๐Ÿงช Testing

API Test with cURL

bash
# 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

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.0

Frontend

  • โ€”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.pth

Solution: Add your trained model to the models/ directory.

CUDA out of memory

RuntimeError: CUDA out of memory

Solution: Reduce batch size or use CPU:

python
DEVICE = torch.device('cpu')

Port already in use

OSError: [Errno 98] Address already in use

Solution: Kill the existing process or use a different port:

bash
lsof -i :8000  # Find process
kill -9 <PID>  # Kill it

Static files not serving

Solution: Ensure the client directory exists and contains index.html:

bash
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

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.Submit a pull request

๐Ÿ“ž Support

For issues and questions, please open a GitHub issue.


Version 1.0.0 | Built with FastAPI, PyTorch & โค๏ธ