Save image using util method and update README with command line argument descriptions

This commit is contained in:
filipstrand 2024-08-19 18:24:52 +02:00
parent a469cce5fe
commit f21a074929
2 changed files with 26 additions and 6 deletions

View File

@ -37,12 +37,29 @@ like [Numpy](https://numpy.org) and [Pillow](https://pypi.org/project/pillow/) f
```
### Generating an image
Run the provided [main.py](main.py)
Run the provided [main.py](main.py) by specifying a prompt and some optional arguments like so:
```
python main.py --prompt "luxury food photograph" --steps 2
python main.py --prompt "Luxury food photograph" --steps 2 --seed 2
```
or make a new separate script like the following
#### Full list of Command-Line Arguments
- **`--prompt`** (required, `str`): Text description of the image to generate.
- **`--output`** (optional, `str`, default: `"image.png"`): Output image filename.
- **`--model`** (optional, `str`, default: `"black-forest-labs/FLUX.1-schnell"`): Model to use for generation.
- **`--seed`** (optional, `int`, default: `0`): Seed for random number generation. Default is time-based.
- **`--height`** (optional, `int`, default: `1024`): Height of the output image in pixels.
- **`--width`** (optional, `int`, default: `1024`): Width of the output image in pixels.
- **`--steps`** (optional, `int`, default: `4`): Number of inference steps.
Or make a new separate script like the following
```python
import sys
@ -60,6 +77,8 @@ image = flux.generate_image(
prompt="Luxury food photograph of a birthday cake. In the middle it has three candles shaped like letters spelling the word 'MLX'. It has perfect lighting and a cozy background with big bokeh and shallow depth of field. The mood is a sunset balcony in tuscany. The photo is taken from the side of the cake. The scene is complemented by a warm, inviting light that highlights the textures and colors of the ingredients, giving it an appetizing and elegant look.",
config=Config(
num_inference_steps=2,
height=768,
width=1360,
)
)

View File

@ -9,6 +9,7 @@ from flux_1_schnell.config.config import Config
from flux_1_schnell.flux import Flux1Schnell
from flux_1_schnell.post_processing.image_util import ImageUtil
def main():
parser = argparse.ArgumentParser(description='Generate an image based on a prompt.')
parser.add_argument('--prompt', type=str, required=True, help='The textual description of the image to generate.')
@ -21,7 +22,7 @@ def main():
args = parser.parse_args()
seed = args.seed or time.time()
seed = args.seed or int(time.time())
flux = Flux1Schnell(args.model)
@ -35,8 +36,8 @@ def main():
)
)
image.save(args.output)
ImageUtil.save_image(image, "image.png")
if __name__ == '__main__':
main()