NAFNet Image Restoration API is a professional-grade, production-ready REST API for image restoration and enhancement. Built with Flask and optimized for high performance, it combines advanced image processing techniques with a modern, intuitive web interface.
POST /api/fixGET /api/info# 1. Clone repository
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
# 2. Install dependencies
pip install -r requirements.txt
# 3. Run application
python app.py
# 4. Open browser
# Navigate to http://localhost:5000
# Build image
docker build -t nafnet-api:latest .
# Run container
docker run -p 5000:5000 nafnet-api:latest
# Access at http://localhost:5000
| Component | Minimum | Recommended | |———–|———|————-| | Python | 3.8 | 3.11 | | RAM | 512MB | 2GB | | Disk | 500MB | 2GB | | CPU | 1 Core | 2+ Cores |
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
# Linux/macOS
python -m venv venv
source venv/bin/activate
# Windows
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
Dependency Details:
Flask 3.1.2 - Web frameworkPillow 12.0.0 - Image processingNumPy 2.3.5 - Numerical computationsSciPy 1.16.3 - Scientific computingWerkzeug 3.1.4 - WSGI utilitiespython app.py
Expected Output:
==================================================
🚀 NAFNet Image Restoration API
==================================================
📍 Running on http://0.0.0.0:5000
🌐 Open in browser: http://localhost:5000
==================================================
# In another terminal
curl http://localhost:5000/api/info
Expected Response:
{
"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"
}
}
http://localhost:5000
Currently no authentication required. For production, implement OAuth 2.0 or API keys.
/api/fixRestore and enhance a single image.
Request:
curl -X POST \
-F "file=@image.jpg" \
http://localhost:5000/api/fix \
-o restored.png
Parameters:
| Parameter | Type | Required | Description |
|———–|——|———-|————-|
| file | File | Yes | Image file (JPG, PNG, WebP, GIF) |
Response:
200 OKimage/pngError Responses:
| Code | Message | Reason |
|——|———|——–|
| 400 | “Upload an image as ‘file’” | Missing file parameter |
| 400 | “No file selected” | Empty filename |
| 500 | “Error message” | Processing error |
/api/infoRetrieve API information and available endpoints.
Request:
curl http://localhost:5000/api/info
Response: 200 OK
{
"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"
}
}
/Access web interface for interactive image restoration.
Response: 200 OK - HTML page with drag-and-drop upload
# Basic restoration
curl -X POST \
-F "file=@photo.jpg" \
http://localhost:5000/api/fix \
-o restored.png
# With verbose output
curl -v -X POST \
-F "file=@photo.jpg" \
http://localhost:5000/api/fix \
-o restored.png
import requests
# Single image
with open('image.jpg', 'rb') as f:
response = requests.post(
'http://localhost:5000/api/fix',
files={'file': f}
)
if response.status_code == 200:
with open('restored.png', 'wb') as out:
out.write(response.content)
print('✓ Image restored successfully')
else:
print(f'✗ Error: {response.status_code}')
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const formData = new FormData();
formData.append('file', file);
fetch('/api/fix', {
method: 'POST',
body: formData
})
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'restored.png';
a.click();
})
.catch(error => console.error('Error:', error));
from api_examples import NAFNetClient
client = NAFNetClient()
# Get API info
info = client.get_info()
# Restore single image
client.restore_image('input.jpg', 'output.png')
# Batch process
client.batch_restore('./images', './restored')
python app.py
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 --timeout 60 app:app
# Build image
docker build -t nafnet-api:latest .
# Run with resource limits
docker run \
-p 5000:5000 \
--memory=1g \
--cpus=1 \
nafnet-api:latest
# With health checks
docker run \
-p 5000:5000 \
--health-cmd='curl localhost:5000/api/info' \
--health-interval=30s \
nafnet-api:latest
version: '3.8'
services:
api:
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
sudo apt-get update
sudo apt-get install python3-pip python3-venv
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
gunicorn -w 4 -b 0.0.0.0:5000 app:app
# Create Procfile
echo "web: gunicorn app:app" > Procfile
# Deploy
git push heroku main
Simply run the project - Replit handles deployment automatically.
┌─────────────────────────────────────────┐
│ Web Interface (HTML/JS) │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Flask Application (app.py) │
│ • Request validation │
│ • Route handling │
│ • Error handling │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Image Processing Pipeline │
│ • Image loading (PIL) │
│ • Denoising (SciPy) │
│ • Enhancement (PIL) │
│ • Saving (PIL) │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Output (PNG Image) │
└─────────────────────────────────────────┘
| Metric | Value | |——–|——-| | Avg Processing Time | 1-2 seconds | | Memory Usage | ~200MB | | CPU Usage | 50-70% | | Max Concurrency | 4 workers | | Throughput | ~30 images/min (single worker) |
| Format | Max Size | |——–|———-| | Input | 50MB | | Output | 30MB (PNG) |
| Format | Input | Output | |——–|——-|——–| | JPEG | ✅ | ✅ | | PNG | ✅ | ✅ | | WebP | ✅ | ✅ | | GIF | ✅ | ✅ |
See DEVELOPMENT.md for comprehensive development guide including:
git clone https://github.com/Gtajisan/NAFNet-Image-Restoration-API.git
cd NAFNet-Image-Restoration-API
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python app.py
We welcome contributions! See CONTRIBUTING.md for guidelines.
git checkout -b feature/amazing-featuregit commit -m 'Add amazing feature'git push origin feature/amazing-featureThis project is licensed under the MIT License - see LICENSE file for details.
MIT License allows:
With conditions:
lsof -i :5000pip install -r requirements.txtReport security vulnerabilities to ffjisan804@gmail.com instead of GitHub Issues.
NAFNet Image Restoration API by Gtajisan