Views
No views yet

1pip install replicate
2export REPLICATE_API_TOKEN=r8_*************************************1import replicate
2
3output = replicate.run(
4 "sdxl-cross-section@sha256:26d3c19f09b63925b3d974d0934cbdf33e7243189f7ff3e281b00930f648fb1d",
5 input={"prompt": "A cross section TOK of an iphone"}
6)
7print(output)diffusers doesn't yet support textual inversion for SDXL, we will use cog-sdxl TokenEmbeddingsHandler class.<s0><s1>1pip install diffusers transformers accelerate safetensors huggingface_hub
2git clone https://github.com/replicate/cog-sdxl cog_sdxl1import torch
2from huggingface_hub import hf_hub_download
3from diffusers import DiffusionPipeline
4from cog_sdxl.dataset_and_utils import TokenEmbeddingsHandler
5from diffusers.models import AutoencoderKL
6
7pipe = DiffusionPipeline.from_pretrained(
8 "stabilityai/stable-diffusion-xl-base-1.0",
9 torch_dtype=torch.float16,
10 variant="fp16",
11).to("cuda")
12
13pipe.load_lora_weights("fofr/sdxl-cross-section", weight_name="lora.safetensors")
14
15text_encoders = [pipe.text_encoder, pipe.text_encoder_2]
16tokenizers = [pipe.tokenizer, pipe.tokenizer_2]
17
18embedding_path = hf_hub_download(repo_id="fofr/sdxl-cross-section", filename="embeddings.pti", repo_type="model")
19embhandler = TokenEmbeddingsHandler(text_encoders, tokenizers)
20embhandler.load_embeddings(embedding_path)
21prompt="A cross section <s0><s1> of an iphone"
22images = pipe(
23 prompt,
24 cross_attention_kwargs={"scale": 0.8},
25).images
26#your output image
27images[0]