Metadata-Version: 2.4
Name: diffused
Version: 1.0.1
Summary: Generate images with diffusion models.
Author-email: Mark <mark@remarkablemark.org>
Maintainer-email: Mark <mark@remarkablemark.org>
License-Expression: MIT
Project-URL: Homepage, https://github.com/ai-action/diffused
Project-URL: Documentation, https://ai-action.github.io/diffused/
Project-URL: Repository, https://github.com/ai-action/diffused
Project-URL: Issues, https://github.com/ai-action/diffused/issues
Project-URL: Changelog, https://github.com/ai-action/diffused/blob/master/CHANGELOG.md
Keywords: ai,artificial intelligence,cli,diffusers,diffusion,image-to-image,inpainting,machine learning,pytorch,stable diffusion,text-to-image
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: accelerate>=1.5.0
Requires-Dist: diffusers>=0.32.0
Requires-Dist: torch>=2.6.0
Requires-Dist: transformers>=4.50.0
Provides-Extra: build
Requires-Dist: build==1.3.0; extra == "build"
Requires-Dist: pyinstaller==6.16.0; extra == "build"
Requires-Dist: twine==6.2.0; extra == "build"
Provides-Extra: docs
Requires-Dist: pdoc==15.0.4; extra == "docs"
Provides-Extra: lint
Requires-Dist: black==25.11.0; extra == "lint"
Requires-Dist: isort==6.1.0; extra == "lint"
Requires-Dist: pre-commit==4.3.0; extra == "lint"
Requires-Dist: ruff==0.14.5; extra == "lint"
Provides-Extra: test
Requires-Dist: coverage==7.10.7; extra == "test"
Requires-Dist: pytest==8.4.2; extra == "test"
Dynamic: license-file

# diffused

[![PyPI version](https://img.shields.io/pypi/v/diffused)](https://pypi.org/project/diffused/)
[![codecov](https://codecov.io/gh/ai-action/diffused/graph/badge.svg?token=fObC6rYkAJ)](https://codecov.io/gh/ai-action/diffused)
[![lint](https://github.com/ai-action/diffused/actions/workflows/lint.yml/badge.svg)](https://github.com/ai-action/diffused/actions/workflows/lint.yml)

🤗 Generate images with diffusion [models](https://huggingface.co/models):

```sh
diffused <model> <prompt>
```

## Quick Start

[Text-to-image](https://huggingface.co/docs/diffusers/using-diffusers/conditional_image_generation):

```sh
pipx run diffused segmind/tiny-sd "red apple"
```

[Image-to-image](https://huggingface.co/docs/diffusers/using-diffusers/img2img):

```sh
pipx run diffused OFA-Sys/small-stable-diffusion-v0 "cat wizard" --image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png
```

[Inpainting](https://huggingface.co/docs/diffusers/en/using-diffusers/inpaint):

```sh
pipx run diffused kandinsky-community/kandinsky-2-2-decoder-inpaint "black cat" --image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png --mask-image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png
```

## Prerequisites

- [Python](https://www.python.org/)
- [pipx](https://pipx.pypa.io/)

## CLI

Install the CLI:

```sh
pipx install diffused
```

### `model`

**Required** (*str*): The diffusion [model](https://huggingface.co/models).

```sh
diffused segmind/SSD-1B "An astronaut riding a green horse"
```

See [segmind/SSD-1B](https://huggingface.co/segmind/SSD-1B).

### `prompt`

**Required** (*str*): The text prompt.

```sh
diffused dreamlike-art/dreamlike-photoreal-2.0 "cinematic photo of Godzilla eating sushi with a cat in a izakaya, 35mm photograph, film, professional, 4k, highly detailed"
```

### `--negative-prompt`

**Optional** (*str*): What to exclude from the output image.

```sh
diffused stabilityai/stable-diffusion-2 "photo of an apple" --negative-prompt="blurry, bright photo, red"
```

With the short option:

```sh
diffused stabilityai/stable-diffusion-2 "photo of an apple" -np="blurry, bright photo, red"
```

### `--image`

**Optional** (*str*): The input image path or URL. The initial image is used as a starting point for an [image-to-image](https://huggingface.co/docs/diffusers/using-diffusers/img2img) diffusion process.

```sh
diffused stabilityai/stable-diffusion-xl-refiner-1.0 "astronaut in a desert" --image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png
```

With the short option:

```sh
diffused stabilityai/stable-diffusion-xl-refiner-1.0 "astronaut in a desert" -i=./local/image.png
```

### `--mask-image`

**Optional** (*str*): The mask image path or URL. [Inpainting](https://huggingface.co/docs/diffusers/en/using-diffusers/inpaint) replaces or edits specific areas of an image. [Create a mask image](https://huggingface.co/docs/diffusers/en/using-diffusers/inpaint#create-a-mask-image) to inpaint images.

```sh
diffused kandinsky-community/kandinsky-2-2-decoder-inpaint "black cat" --image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png --mask-image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png
```

With the short option:

```sh
diffused kandinsky-community/kandinsky-2-2-decoder-inpaint "black cat" -i=inpaint.png -mi=inpaint_mask.png
```

### `--output`

**Optional** (*str*): The output image filename.

```sh
diffused dreamlike-art/dreamlike-photoreal-2.0 "cat eating sushi" --output=cat.jpg
```

With the short option:

```sh
diffused dreamlike-art/dreamlike-photoreal-2.0 "cat eating sushi" -o=cat.jpg
```

### `--width`

**Optional** (*int*): The output image width in pixels.

```sh
diffused stabilityai/stable-diffusion-xl-base-1.0 "dog in space" --width=1024
```

With the short option:

```sh
diffused stabilityai/stable-diffusion-xl-base-1.0 "dog in space" -W=1024
```

### `--height`

**Optional** (*int*): The output image height in pixels.

```sh
diffused stabilityai/stable-diffusion-xl-base-1.0 "dog in space" --height=1024
```

With the short option:

```sh
diffused stabilityai/stable-diffusion-xl-base-1.0 "dog in space" -H=1024
```

### `--number`

**Optional** (*int*): The number of output images. Defaults to 1.

```sh
diffused segmind/tiny-sd apple --number=2
```

With the short option:

```sh
diffused segmind/tiny-sd apple -n=2
```

### `--guidance-scale`

**Optional** (*int*): How much the prompt influences the output image. A lower value leads to more deviation and creativity, whereas a higher value follows the prompt to a tee.

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "astronaut in a jungle" --guidance-scale=7.5
```

With the short option:

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "astronaut in a jungle" -gs=7.5
```

### `--inference-steps`

**Optional** (*int*): The number of diffusion steps used during image generation. The more steps you use, the higher the quality, but the generation time will increase.

```sh
diffused CompVis/stable-diffusion-v1-4 "astronaut rides horse" --inference-steps=50
```

With the short option:

```sh
diffused CompVis/stable-diffusion-v1-4 "astronaut rides horse" -is=50
```

### `--strength`

**Optional** (*float*): The noise added to the input image, which determines how much the output image deviates from the original image. Strength is used for [image-to-image](https://huggingface.co/docs/diffusers/using-diffusers/img2img#strength) and [inpainting](https://huggingface.co/docs/diffusers/using-diffusers/inpaint#strength) tasks and is a multiplier to the number of denoising steps (`--inference-steps`).

```sh
diffused stabilityai/stable-diffusion-xl-refiner-1.0 "astronaut in swamp" --image=https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-sdxl-init.png --strength=0.5
```

With the short option:

```sh
diffused stabilityai/stable-diffusion-xl-refiner-1.0 "astronaut in swamp" -i=image.png -s=0.5
```

### `--seed`

**Optional** (*int*): The seed for generating random numbers, ensuring [reproducibility](https://huggingface.co/docs/diffusers/using-diffusers/reusing_seeds) in image generation pipelines.

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "Labrador in the style of Vermeer" --seed=0
```

With the short option:

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "Labrador in the style of Vermeer" -S=1337
```

### `--device`

**Optional** (*str*): The [device](https://pytorch.org/docs/stable/tensor_attributes.html#torch.device) to accelerate the computation (`cpu`, `cuda`, `mps`, `xpu`, `xla`, or `meta`).

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "astronaut on earth, 8k" --device=cuda
```

With the short option:

```sh
diffused stable-diffusion-v1-5/stable-diffusion-v1-5 "astronaut on earth, 8k" -d=cuda
```

### `--no-safetensors`

**Optional** (*bool*): Whether to disable [safetensors](https://huggingface.co/docs/diffusers/main/en/using-diffusers/using_safetensors).

```sh
diffused runwayml/stable-diffusion-v1-5 "astronaut on mars" --no-safetensors
```

### `--version`

Show the program's version number and exit:

```sh
diffused --version # diffused -v
```

### `--help`

Show the help message and exit:

```sh
diffused --help # diffused -h
```

## Script

Create a virtual environment:

```sh
python3 -m venv .venv
```

Activate the virtual environment:

```sh
source .venv/bin/activate
```

Install the package:

```sh
pip install diffused
```

Generate an image with a [model](https://huggingface.co/segmind/tiny-sd) and a prompt:

```py
# script.py
from diffused import generate

images = generate(model="segmind/tiny-sd", prompt="apple")
images[0].save("apple.png")
```

Run the script:

```sh
python script.py
```

Open the image:

```sh
open apple.png
```

See the [API documentation](https://ai-action.github.io/diffused/diffused/generate.html).

## License

[MIT](https://github.com/ai-action/diffused/blob/master/LICENSE)
