NAFNet-Image-Restoration-API

Installation Guide

Prerequisites

System Requirements

Component Minimum Recommended
RAM 512 MB 2 GB
Disk Space 500 MB 2 GB
CPU 1 Core 2+ Cores
OS Linux, macOS, Windows Linux (Production)

Quick Installation (5 minutes)

Step 1: Clone Repository

git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API

Step 2: Create Virtual Environment

# Linux/macOS
python3 -m venv venv
source venv/bin/activate

# Windows
python -m venv venv
venv\Scripts\activate

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Run Application

python app.py

Step 5: Access Application

Open browser: http://localhost:5000


Detailed Installation

Linux / macOS

1. Clone Repository

git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API

2. Check Python Version

python3 --version  # Should be 3.8 or higher

3. Create Virtual Environment

python3 -m venv venv
source venv/bin/activate

4. Upgrade pip

pip install --upgrade pip

5. Install Dependencies

pip install -r requirements.txt

6. Run Application

python app.py

7. Verify Installation

In another terminal:

curl http://localhost:5000/api/info

Windows

1. Clone Repository

git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API

2. Check Python Version

python --version  # Should be 3.8 or higher

3. Create Virtual Environment

python -m venv venv
venv\Scripts\activate

4. Upgrade pip

python -m pip install --upgrade pip

5. Install Dependencies

pip install -r requirements.txt

6. Run Application

python app.py

7. Access Application

Open browser: http://localhost:5000


Docker Installation

Option 1: Docker CLI

Build Image

docker build -t nafnet-api:latest .

Run Container

docker run -p 5000:5000 nafnet-api:latest

Access Application

Open browser: http://localhost:5000

Option 2: Docker Compose

Create docker-compose.yml

version: '3.8'

services:
  nafnet:
    build: .
    ports:
      - "5000:5000"
    environment:
      - FLASK_ENV=production
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/api/info"]
      interval: 30s
      timeout: 10s
      retries: 3

Run

docker-compose up -d

Verify

docker-compose logs -f

Production Installation

Using Gunicorn

1. Install Gunicorn

pip install gunicorn

2. Run Application

gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 app:app

Parameters:

3. Systemd Service (Linux)

Create /etc/systemd/system/nafnet.service:

[Unit]
Description=NAFNet Image Restoration API
After=network.target

[Service]
Type=notify
User=www-data
WorkingDirectory=/opt/nafnet
Environment="PATH=/opt/nafnet/venv/bin"
ExecStart=/opt/nafnet/venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 app:app

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl enable nafnet
sudo systemctl start nafnet

Cloud Deployment

AWS EC2

1. Launch Instance

2. Connect and Setup

ssh -i key.pem ubuntu@<instance-ip>

# Update system
sudo apt-get update
sudo apt-get upgrade -y

# Install dependencies
sudo apt-get install -y python3-pip python3-venv git

# Clone and setup
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Run with Gunicorn
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:app

3. Setup Nginx Reverse Proxy

sudo apt-get install -y nginx

# Create config at /etc/nginx/sites-available/nafnet
sudo nano /etc/nginx/sites-available/nafnet
server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
sudo ln -s /etc/nginx/sites-available/nafnet /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Heroku

1. Install Heroku CLI

npm install -g heroku
heroku login

2. Create Procfile

web: gunicorn app:app

3. Deploy

git push heroku main

Replit

Replit deployment is automatic - just click the “Publish” button in the web interface.


Verification

Check Installation

# Test API info endpoint
curl http://localhost:5000/api/info

# Expected output (JSON)
{
  "name": "NAFNet Image Restoration API",
  "version": "1.0",
  "endpoints": {
    "GET /": "Web interface",
    "GET /api/info": "Get API info",
    "POST /api/fix": "Upload image for restoration"
  }
}

Test Image Processing

# Create test image
python3 << 'EOF'
from PIL import Image
img = Image.new('RGB', (100, 100), color='red')
img.save('test.jpg')
EOF

# Upload and process
curl -X POST -F "file=@test.jpg" \
  http://localhost:5000/api/fix \
  -o restored.png

# Verify output exists
ls -lh restored.png

Troubleshooting

Issue: Python Command Not Found

Solution:

# Check installation
python3 --version
which python3

# Use python3 instead of python if needed
python3 -m venv venv

Issue: pip: Command Not Found

Solution:

# Install pip
python3 -m ensurepip --upgrade

# Or upgrade pip
python3 -m pip install --upgrade pip

Issue: Permission Denied

Solution:

# Run with sudo (not recommended for venv)
sudo pip install -r requirements.txt

# Or fix permissions
chmod +x app.py

Issue: Port Already in Use

Solution:

# Find process using port 5000
lsof -i :5000

# Kill process
kill -9 <PID>

# Or use different port
# Edit app.py: app.run(port=5001)

Issue: Module ImportError

Solution:

# Reinstall all dependencies
pip install --upgrade -r requirements.txt

# Or individual package
pip install Flask Pillow numpy scipy

Issue: Out of Memory

Solution:

# For Docker, increase memory limit
docker run -p 5000:5000 -m 2g nafnet-api:latest

# For local, increase system RAM or use Gunicorn workers
gunicorn -w 2 -b 0.0.0.0:5000 app:app  # Reduce workers

Issue: Docker Build Fails

Solution:

# Clean Docker cache
docker system prune -a

# Rebuild without cache
docker build --no-cache -t nafnet-api:latest .

Environment Variables

Optional configuration via environment variables:

# Development
export FLASK_ENV=development
export FLASK_DEBUG=1

# Production
export FLASK_ENV=production
export MAX_CONTENT_LENGTH=52428800  # 50MB in bytes

Next Steps

After successful installation:

  1. Read Documentation
  2. Test API
    • Open http://localhost:5000 in browser
    • Upload test images via web interface
    • Try API with cURL or Python
  3. Deploy to Production
    • Use Docker for containerization
    • Setup reverse proxy (Nginx)
    • Configure SSL/TLS with Let’s Encrypt
    • Monitor with health checks
  4. Integrate
    • Use REST API in your applications
    • Implement custom processing pipelines
    • Add authentication and rate limiting

Support

For installation issues:


[← Back to README](/NAFNet-Image-Restoration-API/) | [Go to Development Guide →](/NAFNet-Image-Restoration-API/DEVELOPMENT.html)