logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

68 lines
1.3 KiB

1 year ago
# Image generation using Stable Diffusion
1 year ago
A text2image operator generates image given a text prompt.
This operator is implemented with [Huggingface Diffusers](https://github.com/huggingface/diffusers).
1 year ago
1 year ago
1 year ago
## Code example
```python
from towhee import pipe, ops
pipe = (
pipe.input('prompt')
.map('prompt', 'image', ops.text2image.stable_diffusion())
.output('image')
)
1 year ago
image = pipe('an orange cat')
image.save('an_orange_cat.png')
```
1 year ago
<img src="./an_orange_cat.png" width="800px"/>
1 year ago
<br />
1 year ago
## Factory Constructor
1 year ago
Create the operator via the following factory method:
1 year ago
***text2image.stable_diffusion(model_id='stabilityai/stable-diffusion-2-1', device=None)***
1 year ago
**Parameters:**
1 year ago
***model_id***: *str*
1 year ago
The model id in string, defaults to 'stabilityai/stable-diffusion-2-1'.
1 year ago
Supported model names: [pretrained diffuser models](https://huggingface.co/models?library=diffusers&sort=downloads)
1 year ago
1 year ago
***device***: *str*
1 year ago
The device to running model on, defaults to None.
If None, it will automatically use cuda if gpu is available.
1 year ago
<br />
1 year ago
## Interface
1 year ago
The operator takes a text prompt in string as input.
It loads pretrained diffuser model and generates an image.
1 year ago
***\_\_call\_\_(txt)***
1 year ago
**Parameters:**
1 year ago
***prompt***: *str*
1 year ago
​ The text in string.
1 year ago
**Returns**:
1 year ago
*PIL.Image*
1 year ago
​ The generated image.
1 year ago
<br />