File size: 4,160 Bytes
6c27fdd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import sys
model_name = sys.argv[1]
model_card = f"""---
language:
- en
license: creativeml-openrail-m
tags:
- stable-diffusion
- stable-diffusion-diffusers
- inpainting
- art
- artistic
- diffusers
- anime
- absolute-realism
---
# {model_name.split("/")[-1].replace("-", " ").capitalize()}
`{model_name}` is a Stable Diffusion Inpainting model that has been fine-tuned on [runwayml/stable-diffusion-inpainting](https://huggingface.co/runwayml/stable-diffusion-inpainting).
Please consider supporting me:
- on [Patreon](https://www.patreon.com/Lykon275)
- or [buy me a coffee](https://snipfeed.co/lykon)
## Diffusers
For more general information on how to run inpainting models with 🧨 Diffusers, see [the docs](https://huggingface.co/docs/diffusers/using-diffusers/inpaint).
1. Installation
```
pip install diffusers transformers accelerate
```
2. Run
```py
from diffusers import AutoPipelineForInpainting, DEISMultistepScheduler
import torch
from diffusers.utils import load_image
pipe = AutoPipelineForInpainting.from_pretrained('{model_name}', torch_dtype=torch.float16, variant="fp16")
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.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"
image = load_image(img_url)
mask_image = load_image(mask_url)
prompt = "a majestic tiger sitting on a park bench"
generator = torch.manual_seed(33)
image = pipe(prompt, image=image, mask_image=mask_image, generator=generator, num_inference_steps=25).images[0]
image.save("./image.png")
```
![](./image.png)
"""
"""
## Notes
- **Version 8** focuses on improving what V7 started. Might be harder to do photorealism compared to realism focused models, as it might be hard to do anime compared to anime focused models, but it can do both pretty well if you're skilled enough. Check the examples!
- **Version 7** improves lora support, NSFW and realism. If you're interested in "absolute" realism, try AbsoluteReality.
- **Version 6** adds more lora support and more style in general. It should also be better at generating directly at 1024 height (but be careful with it). 6.x are all improvements.
- **Version 5** is the best at photorealism and has noise offset.
- **Version 4** is much better with anime (can do them with no LoRA) and booru tags. It might be harder to control if you're used to caption style, so you might still want to use version 3.31. V4 is also better with eyes at lower resolutions. Overall is like a "fix" of V3 and shouldn't be too much different.
"""
from huggingface_hub import HfApi
api = HfApi()
read_me_path = "./README.md"
with open(read_me_path, "w") as f:
f.write(model_card)
api.upload_file(
path_or_fileobj=read_me_path,
path_in_repo=read_me_path,
repo_id=model_name,
repo_type="model",
)
from diffusers import AutoPipelineForInpainting, DEISMultistepScheduler
import torch
from diffusers.utils import load_image
pipe = AutoPipelineForInpainting.from_pretrained(model_name, torch_dtype=torch.float16, variant="fp16")
pipe.scheduler = DEISMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.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"
image = load_image(img_url)
mask_image = load_image(mask_url)
prompt = "a majestic tiger sitting on a park bench"
generator = torch.manual_seed(33)
image = pipe(prompt, image=image, mask_image=mask_image, generator=generator, num_inference_steps=25).images[0]
image.save("./image.png")
image_path = "./image.png"
image.save(image_path)
api.upload_file(
path_or_fileobj=image_path,
path_in_repo=image_path,
repo_id=model_name,
repo_type="model",
)
pipe.push_to_hub(model_name, variant="fp16")
|