# Stable Diffusion Upscale

Stable Diffusion upscale is a script in the original Automatic 1111 Web UI that performs upscaling with an upscaler - like Esrgan or RealEsrgan - followed by an image to image to enhance details in the upscaled image. With Auto 1111 SDK, you can perform this in a few lines of code:

1. Initialize your pipelines. This requires initializing both a Stable Diffusion Pipeline and an upscaler pipeline. The upscaler pipeline can be any one of your choice (Esrgan or RealEsrgan)

```
from auto1111sdk import StableDiffusionPipeline, EsrganPipeline

upscaler = EsrganPipeline("<PATH TO YOUR LOCAL PTH WEIGHTS FILE>")
pipe = StableDiffusionPipeline("<PATH TO YOUR LOCAL MODEL SAFETENSORS FILE>")
```

2. Load the initial image

```
from PIL import Image

image = Image.open("init.png")
```

3. Run the SD Upscale

```
output = pipe.sd_upscale_img2img(upscaler=upscaler, prompt=prompt, negative_prompt=negative_prompt, init_images=image)
```

You're gonna want to use the exact same prompt/negative prompt you used to generate the original image. If you don't have that, then use a prompt like "high quality". For a more comprehensive tutorial on how to use SD upscale, read this article: <https://stable-diffusion-art.com/ai-upscaler/>.

***

### Parameters

Currently, Auto 1111 SDK supports the following parameters (and the corresponding default values) for Stable Diffusion Upscale:

```python
init_image: a PIL Image object
prompt: str
negative_prompt: str = ''
seed: int = -1
steps: int = 20
cfg_scale: float = 7.5
num_images: int = 1
sampler_name: str = "Euler"
denoising_strength: float = 0.75
scale_factor: int = 2 # the scale by which you want to upscale your image by
overlap: int = 64
upscaler # Should be either an instance of EsrganPipeline or RealEsrganPipeline
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flush-ai.gitbook.io/automatic-1111-sdk/pipelines/stable-diffusion-upscale.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
