-
Notifications
You must be signed in to change notification settings - Fork 470
Add Use this model
snippets for top diffusers models
#1642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,8 +434,63 @@ pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}") | |
pipe.load_textual_inversion("${model.id}")`, | ||
]; | ||
|
||
const diffusers_flux_fill = (model: ModelData) => [ | ||
`import torch | ||
from diffusers import FluxFillPipeline | ||
from diffusers.utils import load_image | ||
|
||
image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup.png") | ||
mask = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup_mask.png") | ||
|
||
pipe = FluxFillPipeline.from_pretrained("${model.id}", torch_dtype=torch.bfloat16).to("cuda") | ||
image = pipe( | ||
prompt="a white paper cup", | ||
image=image, | ||
mask_image=mask, | ||
height=1632, | ||
width=1232, | ||
guidance_scale=30, | ||
num_inference_steps=50, | ||
max_sequence_length=512, | ||
generator=torch.Generator("cpu").manual_seed(0) | ||
).images[0] | ||
image.save(f"flux-fill-dev.png")`, | ||
]; | ||
|
||
const diffusers_inpainting = (model: ModelData) => [ | ||
`import torch | ||
from diffusers import AutoPipelineForInpainting | ||
from diffusers.utils import load_image | ||
|
||
pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", torch_dtype=torch.float16, variant="fp16").to("cuda") | ||
|
||
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png" | ||
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png" | ||
Comment on lines
+467
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) store on Hub maybe? |
||
|
||
image = load_image(img_url).resize((1024, 1024)) | ||
mask_image = load_image(mask_url).resize((1024, 1024)) | ||
|
||
prompt = "a tiger sitting on a park bench" | ||
generator = torch.Generator(device="cuda").manual_seed(0) | ||
|
||
image = pipe( | ||
prompt=prompt, | ||
image=image, | ||
mask_image=mask_image, | ||
guidance_scale=8.0, | ||
num_inference_steps=20, # steps between 15 and 30 work well for us | ||
strength=0.99, # make sure to use \`strength\` below 1.0 | ||
generator=generator, | ||
).images[0]`, | ||
]; | ||
|
||
export const diffusers = (model: ModelData): string[] => { | ||
if (model.tags.includes("controlnet")) { | ||
if ( | ||
model.tags.includes("StableDiffusionInpaintPipeline") || | ||
model.tags.includes("StableDiffusionXLInpaintPipeline") | ||
) { | ||
return diffusers_inpainting(model); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example that doesn't need extra libraries to install |
||
} else if (model.tags.includes("controlnet")) { | ||
return diffusers_controlnet(model); | ||
} else if (model.tags.includes("lora")) { | ||
if (model.pipeline_tag === "image-to-image") { | ||
|
@@ -449,6 +504,8 @@ export const diffusers = (model: ModelData): string[] => { | |
} | ||
} else if (model.tags.includes("textual_inversion")) { | ||
return diffusers_textual_inversion(model); | ||
} else if (model.tags.includes("FluxFillPipeline")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example that doesn't need extra libraries to install |
||
return diffusers_flux_fill(model); | ||
} else if (model.pipeline_tag === "image-to-video") { | ||
return diffusers_image_to_video(model); | ||
} else if (model.pipeline_tag === "image-to-image") { | ||
|
Uh oh!
There was an error while loading. Please reload this page.