File size: 3,303 Bytes
adf2fff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# CodeFormer API Documentation

This document describes the programmatic interface for the CodeFormer Face Restoration service.

## Base URL
The API is accessible at:
`https://esmailx50-job.hf.space` (or your specific Hugging Face Space URL)

---

## 1. Process Images
Processes one or more images for face restoration and enhancement.

- **Endpoint:** `/api/process`
- **Method:** `POST`
- **Consumes:** `multipart/form-data` OR `application/json`

### Parameters
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `fidelity` | float | `0.5` | Fidelity weight ($w$). Range [0, 1]. Lower is more "hallucinated" detail, higher is more identity preservation. |
| `upscale` | int | `2` | Final upscaling factor. Supported: `1`, `2`, `4`. |
| `background_enhance` | bool | `false` | Enhance the background using Real-ESRGAN. |
| `face_upsample` | bool | `false` | Upsample restored faces using Real-ESRGAN. |
| `return_base64` | bool | `false` | If true, includes the processed image as a base64 string in the JSON response. |

### Input Formats

#### A. Multipart Form Data (`multipart/form-data`)
Useful for uploading files directly.
- `image`: One or more image files (as a list).
- Other parameters as form fields.

**Example (curl):**
```bash

curl -X POST 

  -F "image=@my_photo.jpg" 

  -F "fidelity=0.7" 

  -F "background_enhance=true" 

  https://esmailx50-job.hf.space/api/process

```

#### B. JSON (`application/json`)
Useful for sending base64-encoded image data.
- `image_base64`: A single base64 string (with or without data URI prefix).
- `images_base64`: (Optional) A list of base64 strings for batch processing.
- Other parameters as JSON keys.

**Example (curl):**
```bash

curl -X POST 

  -H "Content-Type: application/json" 

  -d '{

    "image_base64": "data:image/png;base64,iVBORw0KG...",

    "fidelity": 0.5,

    "return_base64": true

  }' 

  https://esmailx50-job.hf.space/api/process

```

### Success Response
```json

{

  "status": "success",

  "count": 1,

  "results": [

    {

      "original_name": "image.png",

      "filename": "api_result_uuid.png",

      "image_url": "https://.../static/results/api_result_uuid.png",

      "image_base64": "iVBORw0KG..." // Only if return_base64 was true

    }

  ]

}

```

### Error Response
```json

{

  "status": "error",

  "message": "Detailed error message here"

}

```

---

## 2. Health Check
Checks if the service is online and returns the compute device being used.

- **Endpoint:** `/api/health`
- **Method:** `GET`

**Success Response:**
```json

{

  "status": "online",

  "device": "cuda" // or "cpu"

}

```

---

## CORS & Integration
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.

**Javascript Example (Fetch):**
```javascript

const formData = new FormData();

formData.append('image', fileInput.files[0]);

formData.append('fidelity', '0.5');



const response = await fetch('https://esmailx50-job.hf.space/api/process', {

  method: 'POST',

  body: formData

});

const data = await response.json();

console.log(data.results[0].image_url);

```