Esmaill1 commited on
Commit ·
9a5c1e4
1
Parent(s): cabbee4
Add API documentation for programmatic access
Browse files- API_DOCUMENTATION.md +118 -0
API_DOCUMENTATION.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CodeFormer API Documentation
|
| 2 |
+
|
| 3 |
+
This document describes the programmatic interface for the CodeFormer Face Restoration service.
|
| 4 |
+
|
| 5 |
+
## Base URL
|
| 6 |
+
The API is accessible at:
|
| 7 |
+
`https://esmailx50-job.hf.space` (or your specific Hugging Face Space URL)
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## 1. Process Images
|
| 12 |
+
Processes one or more images for face restoration and enhancement.
|
| 13 |
+
|
| 14 |
+
- **Endpoint:** `/api/process`
|
| 15 |
+
- **Method:** `POST`
|
| 16 |
+
- **Consumes:** `multipart/form-data` OR `application/json`
|
| 17 |
+
|
| 18 |
+
### Parameters
|
| 19 |
+
| Parameter | Type | Default | Description |
|
| 20 |
+
| :--- | :--- | :--- | :--- |
|
| 21 |
+
| `fidelity` | float | `0.5` | Fidelity weight ($w$). Range [0, 1]. Lower is more "hallucinated" detail, higher is more identity preservation. |
|
| 22 |
+
| `upscale` | int | `2` | Final upscaling factor. Supported: `1`, `2`, `4`. |
|
| 23 |
+
| `background_enhance` | bool | `false` | Enhance the background using Real-ESRGAN. |
|
| 24 |
+
| `face_upsample` | bool | `false` | Upsample restored faces using Real-ESRGAN. |
|
| 25 |
+
| `return_base64` | bool | `false` | If true, includes the processed image as a base64 string in the JSON response. |
|
| 26 |
+
|
| 27 |
+
### Input Formats
|
| 28 |
+
|
| 29 |
+
#### A. Multipart Form Data (`multipart/form-data`)
|
| 30 |
+
Useful for uploading files directly.
|
| 31 |
+
- `image`: One or more image files (as a list).
|
| 32 |
+
- Other parameters as form fields.
|
| 33 |
+
|
| 34 |
+
**Example (curl):**
|
| 35 |
+
```bash
|
| 36 |
+
curl -X POST
|
| 37 |
+
-F "image=@my_photo.jpg"
|
| 38 |
+
-F "fidelity=0.7"
|
| 39 |
+
-F "background_enhance=true"
|
| 40 |
+
https://esmailx50-job.hf.space/api/process
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
#### B. JSON (`application/json`)
|
| 44 |
+
Useful for sending base64-encoded image data.
|
| 45 |
+
- `image_base64`: A single base64 string (with or without data URI prefix).
|
| 46 |
+
- `images_base64`: (Optional) A list of base64 strings for batch processing.
|
| 47 |
+
- Other parameters as JSON keys.
|
| 48 |
+
|
| 49 |
+
**Example (curl):**
|
| 50 |
+
```bash
|
| 51 |
+
curl -X POST
|
| 52 |
+
-H "Content-Type: application/json"
|
| 53 |
+
-d '{
|
| 54 |
+
"image_base64": "data:image/png;base64,iVBORw0KG...",
|
| 55 |
+
"fidelity": 0.5,
|
| 56 |
+
"return_base64": true
|
| 57 |
+
}'
|
| 58 |
+
https://esmailx50-job.hf.space/api/process
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### Success Response
|
| 62 |
+
```json
|
| 63 |
+
{
|
| 64 |
+
"status": "success",
|
| 65 |
+
"count": 1,
|
| 66 |
+
"results": [
|
| 67 |
+
{
|
| 68 |
+
"original_name": "image.png",
|
| 69 |
+
"filename": "api_result_uuid.png",
|
| 70 |
+
"image_url": "https://.../static/results/api_result_uuid.png",
|
| 71 |
+
"image_base64": "iVBORw0KG..." // Only if return_base64 was true
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
}
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Error Response
|
| 78 |
+
```json
|
| 79 |
+
{
|
| 80 |
+
"status": "error",
|
| 81 |
+
"message": "Detailed error message here"
|
| 82 |
+
}
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## 2. Health Check
|
| 88 |
+
Checks if the service is online and returns the compute device being used.
|
| 89 |
+
|
| 90 |
+
- **Endpoint:** `/api/health`
|
| 91 |
+
- **Method:** `GET`
|
| 92 |
+
|
| 93 |
+
**Success Response:**
|
| 94 |
+
```json
|
| 95 |
+
{
|
| 96 |
+
"status": "online",
|
| 97 |
+
"device": "cuda" // or "cpu"
|
| 98 |
+
}
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
## CORS & Integration
|
| 104 |
+
Cross-Origin Resource Sharing (CORS) is enabled for all routes. This allows you to call the API directly from browser-based applications (React, Vue, etc.) without hitting "Same-Origin Policy" blocks.
|
| 105 |
+
|
| 106 |
+
**Javascript Example (Fetch):**
|
| 107 |
+
```javascript
|
| 108 |
+
const formData = new FormData();
|
| 109 |
+
formData.append('image', fileInput.files[0]);
|
| 110 |
+
formData.append('fidelity', '0.5');
|
| 111 |
+
|
| 112 |
+
const response = await fetch('https://esmailx50-job.hf.space/api/process', {
|
| 113 |
+
method: 'POST',
|
| 114 |
+
body: formData
|
| 115 |
+
});
|
| 116 |
+
const data = await response.json();
|
| 117 |
+
console.log(data.results[0].image_url);
|
| 118 |
+
```
|