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

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