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

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