Views
No views yet


1import torch
2from diffusers import DiffusionPipeline
3def make_prompt(prompt: str) -> str:
4 prompt_prefix = "RAW photo"
5 prompt_suffix = "(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3"
6 return ", ".join([prompt_prefix, prompt, prompt_suffix]).strip()
7def make_negative_prompt(negative_prompt: str) -> str:
8 negative_prefix = "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), \
9 text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, \
10 extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, \
11 bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, \
12 extra arms, extra legs, fused fingers, too many fingers, long neck"
13 return (
14 ", ".join([negative_prefix, negative_prompt]).strip()
15 if len(negative_prompt) > 0
16 else negative_prefix
17 )
18device = "cuda" if torch.cuda.is_available() else "cpu"
19model_id = "aldente0630/musinsaigo-3.0"
20pipe = DiffusionPipeline.from_pretrained(
21 "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
22)
23pipe = pipe.to(device)
24pipe.load_lora_weights(model_id)
25# Write your prompt here.
26PROMPT = "a korean woman wearing a white t - shirt and black pants with a bear on it"
27NEGATIVE_PROMPT = ""
28# If you're not using a refiner
29image = pipe(
30 prompt=make_prompt(PROMPT),
31 height=1024,
32 width=768,
33 num_inference_steps=50,
34 guidance_scale=7.5,
35 negative_prompt=make_negative_prompt(NEGATIVE_PROMPT),
36 cross_attention_kwargs={"scale": 0.75},
37).images[0]
38# If you're using a refiner
39refiner = DiffusionPipeline.from_pretrained(
40 "stabilityai/stable-diffusion-xl-refiner-1.0",
41 text_encoder_2=pipe.text_encoder_2,
42 vae=pipe.vae,
43 torch_dtype=torch.float16,
44)
45refiner = refiner.to(device)
46image = pipe(
47 prompt=make_prompt(PROMPT),
48 height=1024,
49 width=768,
50 num_inference_steps=50,
51 guidance_scale=7.5,
52 negative_prompt=make_negative_prompt(NEGATIVE_PROMPT),
53 output_type="latent",
54 cross_attention_kwargs={"scale": 0.75},
55)["images"]
56generated_images = refiner(
57 prompt=make_prompt(PROMPT),
58 image=image,
59 num_inference_steps=50,
60)["images"]
61image.save("test.png")