patrickvonplaten
commited on
Commit
•
18ff08e
1
Parent(s):
9ae8cf2
up
Browse files- cat.pt +3 -0
- dog.pt +3 -0
- run_pix2pix0.py +54 -0
cat.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aa9441dc014d5e86567c5ef165e10b50d2a7b3a68d90686d0cd1006792adf334
|
3 |
+
size 237300
|
dog.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:becf079d61d7f35727bcc0d8506ddcdcddb61e62d611840ff3d18eca7fb6338c
|
3 |
+
size 237300
|
run_pix2pix0.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# https://github.com/pix2pixzero/pix2pix-zero/blob/main/src/edit_synthetic.py
|
6 |
+
import requests
|
7 |
+
|
8 |
+
from diffusers import DDIMScheduler, StableDiffusionPix2PixZeroPipeline
|
9 |
+
|
10 |
+
api = HfApi()
|
11 |
+
|
12 |
+
|
13 |
+
def download(embedding_url, local_filepath):
|
14 |
+
r = requests.get(embedding_url)
|
15 |
+
with open(local_filepath, "wb") as f:
|
16 |
+
f.write(r.content)
|
17 |
+
|
18 |
+
|
19 |
+
model_ckpt = "CompVis/stable-diffusion-v1-4"
|
20 |
+
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
|
21 |
+
model_ckpt, conditions_input_image=False, torch_dtype=torch.float16
|
22 |
+
)
|
23 |
+
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
|
24 |
+
pipeline.to("cuda")
|
25 |
+
|
26 |
+
|
27 |
+
prompt = "a high resolution painting of a cat in the style of van gough"
|
28 |
+
source_embedding_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt"
|
29 |
+
target_embedding_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt"
|
30 |
+
|
31 |
+
for url in [source_embedding_url, target_embedding_url]:
|
32 |
+
download(url, url.split("/")[-1])
|
33 |
+
|
34 |
+
source_embeds = torch.load(source_embedding_url.split("/")[-1])
|
35 |
+
target_embeds = torch.load(target_embedding_url.split("/")[-1])
|
36 |
+
|
37 |
+
image = pipeline(
|
38 |
+
prompt,
|
39 |
+
source_embeds=source_embeds,
|
40 |
+
target_embeds=target_embeds,
|
41 |
+
num_inference_steps=50,
|
42 |
+
cross_attention_guidance_amount=0.15,
|
43 |
+
).images[0]
|
44 |
+
|
45 |
+
path = "/home/patrick_huggingface_co/images/aa.png"
|
46 |
+
image.save(path)
|
47 |
+
|
48 |
+
api.upload_file(
|
49 |
+
path_or_fileobj=path,
|
50 |
+
path_in_repo=path.split("/")[-1],
|
51 |
+
repo_id="patrickvonplaten/images",
|
52 |
+
repo_type="dataset",
|
53 |
+
)
|
54 |
+
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
|