Verifying the work
After the not-so-many lines of code, we finally have all the logic ready, so let’s give the code a test.
In the simple version of a long prompt encoder, we still get a cat with some patterns in the body instead of pure white
, as we gave in the prompt. Now, let’s add weight to the white
keyword to see whether anything happens:
prompt = "photo, cute cat running on the grass" * 10 prompt = prompt + ",pure (white:1.5) cat" * 10 neg_prompt = "low resolution, bad anatomy" prompt_embeds, prompt_neg_embeds = get_weighted_text_embeddings( Â Â Â Â pipe, prompt = prompt, neg_prompt = neg_prompt ) image = pipe( Â Â Â Â prompt_embeds = prompt_embeds, Â Â Â Â negative_prompt_embeds = prompt_neg_embeds, Â Â Â Â generator = torch.Generator("cuda").manual_seed(1) ).images[0] image
Our new embedding function magically enabled us to generate a pure white cat...