Created
August 14, 2024 09:18
-
-
Save recoilme/c20a8cb5c4f06997c8f64be06cf24731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffusers import StableDiffusionXLPipeline | |
from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl | |
from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl_2p | |
from sd_embed.embedding_funcs import group_tokens_and_weights | |
from sd_embed.prompt_parser import parse_prompt_attention | |
from diffusers import DiffusionPipeline,EulerAncestralDiscreteScheduler | |
from transformers import CLIPTextModel, CLIPTextModelWithProjection, CLIPTokenizer | |
from diffusers.utils import make_image_grid | |
import torch, gc | |
MODEL_PATH = "models/colorfulxl" | |
pipe = StableDiffusionXLPipeline.from_pretrained( | |
MODEL_PATH, | |
torch_dtype=torch.float16, | |
variant="fp16", | |
use_safetensors=True | |
).to('cuda') | |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config( | |
pipe.scheduler.config, | |
) | |
prompt = "The image captures a vibrant scene from a bustling street. The perspective is from a pedestrian's viewpoint on the sidewalk, immersing the viewer in the city's daily life. The street is lined with a variety of buildings, their architecture hinting at the rich history of the city. Among these structures, a church with a tall bell tower stands out, its presence adding a sense of grandeur to the scene.People are seen walking on the sidewalk, going about their day, adding a dynamic element to the otherwise static urban landscape.The colors in the image are predominantly blue, yellow, and green, reflecting the lively atmosphere of the city. The sky above is a clear blue, suggesting a sunny day, which further enhances the overall vibrancy of the scene." | |
#prompt = "The image captures a serene scene on a river. Dominating the foreground is a wooden boat, its brown hue contrasting with the greenish-blue of the water. The boat is not alone in the frame. In the background, a red-roofed building can be seen, its white walls standing out against the greenery. The building is partially obscured by trees, adding an element of mystery to the scene. The sky above is overcast, casting a soft light over the entire scene. Despite this, there's a sense of tranquility that pervades the image, as if inviting the viewer to take a moment and appreciate the peacefulness of the scene. There's no text or discernible action in the image, just a snapshot of a moment, frozen in time." | |
prompt = "A whimsical and creative image depicting a hybrid creature that is a mix of a waffle and a hippopotamus. This imaginative creature features the distinctive, bulky body of a hippo, but with a texture and appearance resembling a golden-brown, crispy waffle. The creature might have elements like waffle squares across its skin and a syrup-like sheen. It's set in a surreal environment that playfully combines a natural water habitat of a hippo with elements of a breakfast table setting, possibly including oversized utensils or plates in the background. The image should evoke a sense of playful absurdity and culinary fantasy." | |
#prompt = "Studio Ghibli ~ Hayao Miyazaki ~ Spirited Away ~ beautiful ultra detailed illustration of a cute witch of the sitting on a tree stump reading a book, her ornate robe reminiscent of the stars in the night sky. This contrast between the fantastical character and the more bold color scheme and elements gives the piece an intriguing narrative quality. painted realism, photorealistic, 8k, fantasy digital art, HDR, UHD." | |
#prompt = "In a dark forest stands an old abandoned castle on the top of a hill, surrounded by dense trees with branches hanging down to the ground, which hide it from prying eyes with their gloomy cover of moss lichen. This castle is inhabited by a spirit of revenge the ghost of a woman named Lilith, who was brutally murdered here many centuries ago for her forbidden desires for power over peoples lives" | |
negative_prompt = "" | |
#prompt = prompt.replace("...", ".") | |
#prompt = prompt.replace("!", ".") | |
#prompt = prompt.replace(".", "\n") | |
generator = torch.Generator(device="cuda").manual_seed(42) | |
pipe.enable_vae_slicing() | |
prompt_embeds, prompt_neg_embeds, pooled_prompt_embeds, negative_pooled_prompt_embeds = get_weighted_text_embeddings_sdxl( | |
pipe | |
, prompt = prompt | |
, neg_prompt = negative_prompt | |
) | |
image2 = pipe( | |
prompt_embeds=prompt_embeds, | |
pooled_prompt_embeds=pooled_prompt_embeds, | |
negative_prompt_embeds=prompt_neg_embeds, | |
negative_pooled_prompt_embeds=negative_pooled_prompt_embeds, | |
num_inference_steps=24, | |
guidance_scale=2, | |
generator=generator, | |
num_images_per_prompt=2 | |
).images | |
grid = make_image_grid([image2[0], image2[1]], rows=1, cols=2) | |
grid.save("sample.png") | |
display(grid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment