This repository has been archived on 2025-09-28. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
sdxl-cli/sdxl.py

30 lines
1.2 KiB
Python
Raw Permalink Normal View History

2024-01-05 19:39:15 +01:00
#!/usr/bin/env python3
# Copyright (c) 2024 Julian Müller (ChaoticByte)
from argparse import ArgumentParser
from diffusers import AutoPipelineForText2Image
if __name__ == "__main__":
# parse cmdline args
argp = ArgumentParser()
argp.add_argument("-m", "--model", type=str, help="Path to the sdxl model folder", required=True)
argp.add_argument("-p", "--prompt", type=str, help="Prompt for image inference")
argp.add_argument("-n", "--steps", type=int, help="Number of inference steps", default=1)
argp.add_argument("-o", "--output", type=str, help="Image output file", default="output.png")
args = argp.parse_args()
# create pipeline, process prompt(s), output file
pipe = AutoPipelineForText2Image.from_pretrained(args.model, local_files_only=True)
pipe.to("cpu")
if args.prompt is None:
try:
while True:
prompt = input("> ")
pipe(prompt=prompt, num_inference_steps=args.steps, guidance_scale=0.0).images[0].save(args.output)
except (EOFError, KeyboardInterrupt):
print("bye.")
exit(0)
else:
pipe(prompt=args.prompt, num_inference_steps=args.steps, guidance_scale=0.0).images[0].show(args.output)