sayakpaul HF staff commited on
Commit
87177cf
1 Parent(s): 0dfdf9a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +88 -1
README.md CHANGED
@@ -24,4 +24,91 @@ dataset_info:
24
  ---
25
  # Dataset Card for "sdxl-0.9"
26
 
27
- [More Information needed](https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ---
25
  # Dataset Card for "sdxl-0.9"
26
 
27
+ Dataset was generated using the code below:
28
+
29
+ ```python
30
+ import torch
31
+ from datasets import Dataset, Features
32
+ from datasets import Image as ImageFeature
33
+ from datasets import Value, load_dataset
34
+
35
+ from diffusers import DDIMScheduler, DiffusionPipeline
36
+ import PIL
37
+
38
+
39
+ def main():
40
+ print("Loading dataset...")
41
+ parti_prompts = load_dataset("nateraw/parti-prompts", split="train")
42
+
43
+ print("Loading pipeline...")
44
+ ckpt_id = "stabilityai/stable-diffusion-xl-base-0.9"
45
+ pipe = DiffusionPipeline.from_pretrained(
46
+ ckpt_id, torch_dtype=torch.float16, use_auth_token=True
47
+ ).to("cuda")
48
+ pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
49
+ pipe.set_progress_bar_config(disable=True)
50
+
51
+ seed = 0
52
+ generator = torch.Generator("cuda").manual_seed(seed)
53
+
54
+ print("Running inference...")
55
+ main_dict = {}
56
+ for i in range(len(parti_prompts)):
57
+ sample = parti_prompts[i]
58
+ prompt = sample["Prompt"]
59
+ image = pipe(
60
+ prompt,
61
+ generator=generator,
62
+ num_inference_steps=100,
63
+ guidance_scale=7.5,
64
+ ).images[0]
65
+
66
+ image = image.resize((256, 256), resample=PIL.Image.Resampling.LANCZOS)
67
+ img_path = f"sd_xl_{i}.png"
68
+ image.save(img_path)
69
+ main_dict.update(
70
+ {
71
+ prompt: {
72
+ "img_path": img_path,
73
+ "Category": sample["Category"],
74
+ "Challenge": sample["Challenge"],
75
+ "Note": sample["Note"],
76
+ "model_name": ckpt_id,
77
+ "seed": seed,
78
+ }
79
+ }
80
+ )
81
+
82
+ def generation_fn():
83
+ for prompt in main_dict:
84
+ prompt_entry = main_dict[prompt]
85
+ yield {
86
+ "Prompt": prompt,
87
+ "Category": prompt_entry["Category"],
88
+ "Challenge": prompt_entry["Challenge"],
89
+ "Note": prompt_entry["Note"],
90
+ "images": {"path": prompt_entry["img_path"]},
91
+ "model_name": prompt_entry["model_name"],
92
+ "seed": prompt_entry["seed"],
93
+ }
94
+
95
+ print("Preparing HF dataset...")
96
+ ds = Dataset.from_generator(
97
+ generation_fn,
98
+ features=Features(
99
+ Prompt=Value("string"),
100
+ Category=Value("string"),
101
+ Challenge=Value("string"),
102
+ Note=Value("string"),
103
+ images=ImageFeature(),
104
+ model_name=Value("string"),
105
+ seed=Value("int64"),
106
+ ),
107
+ )
108
+ ds_id = "diffusers-parti-prompts/sdxl-0.9"
109
+ ds.push_to_hub(ds_id)
110
+
111
+
112
+ if __name__ == "__main__":
113
+ main()
114
+ ```