File size: 3,306 Bytes
e4c1ae7
 
 
 
 
 
 
 
b53c233
e4c1ae7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Image Enhancer

High-resolution image enhancement powered by AI.

## Before / After Example

| Before                                                           | After                                                                                                 |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| ![Before](demo/download.jpg) | ![After](demo/download_out.jpg) |

## Description

This application provides a simple web interface to enhance images using an AI upscaling model. Upload your low-resolution images and get high-resolution results.

## Features

- Web UI for easy image uploading and enhancement.
- API endpoint for programmatic access (`/enhance`).
- Selectable upscaling models and scale factors.
- Optional face enhancement.
- Input and output images are saved in `api_inputs` and `api_outputs` respectively.

## Installation

1.  **Clone the repository:**
    ```bash
    git clone https://huggingface.co/sayed99/Image-Enhancer
    cd Image-Enhancer
    ```
2.  **Create Conda Environment:**
    Set up the necessary environment using the provided `environment.yml` file:

    ```bash
    conda env create -f environment.yml
    conda activate esrgan-env
    ```

    _(Note: The environment name is defined within the `environment.yml` file)_

3.  **Download Model Weights:**
    The required model weights (`.pth` files) need to be placed in the `Real-ESRGAN/weights/` directory. Common models include:
    - `RealESRGAN_x4plus.pth`
    - `RealESRGAN_x2plus.pth`
      You can usually find these linked from the original Real-ESRGAN repository or other model sources.

## Usage

Run the application using the provided script:

```bash
python run.py
```

This will:

1.  Start the backend API server (usually on `http://localhost:8000`).
2.  Start the Streamlit web interface (usually on `http://localhost:8501`).
3.  Open the web interface in your default browser.

Navigate to the web interface, upload an image, select your desired options (model, scale, face enhancement), and click "Enhance Image".

## API Usage

You can also interact with the API directly.

**Enhance Endpoint:** `POST /enhance/`

**Form Data:**

- `file`: The image file to upload.
- `model_name` (optional, default: `RealESRGAN_x4plus`): Model to use (e.g., `RealESRGAN_x4plus`, `RealESRGAN_x2plus`).
- `outscale` (optional, default: `4.0`): The desired output scale factor (e.g., `2.0`, `4.0`).
- `face_enhance` (optional, default: `false`): Boolean flag to enable face enhancement.
- `fp32` (optional, default: `false`): Boolean flag to use FP32 precision.

**Example using `curl`:**

```bash
curl -X POST "http://localhost:8000/enhance/" \
     -F "file=@/path/to/your/image.jpg" \
     -F "model_name=RealESRGAN_x4plus" \
     -F "outscale=4.0" \
     -o enhanced_image.jpg
```

## Notes

- Ensure the API server is running before using the Streamlit app or sending direct API requests.
- The application uses significant resources (RAM, potentially GPU if configured).
- Input images are saved in the `api_inputs` directory.
- Output images are saved in subdirectories within the `api_outputs` directory, named by a unique request ID.

---

Powered by Real-ESRGAN