weathon
commited on
Commit
·
c5c2ec0
1
Parent(s):
2eef6b6
compared with no guidance
Browse files
app.py
CHANGED
|
@@ -56,16 +56,18 @@ scheduler = CommitScheduler(
|
|
| 56 |
every=1
|
| 57 |
)
|
| 58 |
|
| 59 |
-
def save_image(prompt: str, negative_prompt: str, img_vsf: Image, img_nag: Image, parameters: dict) -> None:
|
| 60 |
vsf_image_path = IMAGE_DATASET_DIR / f"{uuid4()}_vsf.png"
|
| 61 |
nag_image_path = IMAGE_DATASET_DIR / f"{uuid4()}_nag.png"
|
|
|
|
| 62 |
|
| 63 |
with scheduler.lock:
|
| 64 |
img_vsf.save(vsf_image_path)
|
| 65 |
img_nag.save(nag_image_path)
|
|
|
|
| 66 |
with IMAGE_JSONL_PATH.open("a") as f:
|
| 67 |
-
json.dump({"prompt": prompt, "negative_prompt": negative_prompt, "vsf_image_path": str(vsf_image_path), "nag_image_path": str(nag_image_path), "parameters": parameters, "timestamp": datetime.utcnow().isoformat()}, f)
|
| 68 |
-
f.write("\n")
|
| 69 |
|
| 70 |
|
| 71 |
pipe = pipe.to("cuda")
|
|
@@ -104,8 +106,19 @@ def generate_video(positive_prompt, negative_prompt, guidance_scale, bias, step,
|
|
| 104 |
).images[0]
|
| 105 |
nag_path = f"images/{uuid.uuid4().hex}_nag.png"
|
| 106 |
output_nag.save(nag_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
print(f"NAG Image saved to {nag_path}")
|
| 108 |
-
save_image(positive_prompt, negative_prompt, output, output_nag, {
|
| 109 |
"guidance_scale": guidance_scale,
|
| 110 |
"bias": bias,
|
| 111 |
"step": step,
|
|
@@ -115,7 +128,7 @@ def generate_video(positive_prompt, negative_prompt, guidance_scale, bias, step,
|
|
| 115 |
"nag_tau": nag_tau,
|
| 116 |
"nag_step": nag_step,
|
| 117 |
})
|
| 118 |
-
return output_path, nag_path
|
| 119 |
|
| 120 |
import json
|
| 121 |
with open("sample_prompts.json", "r") as f:
|
|
@@ -215,10 +228,10 @@ with gr.Blocks(title="Value Sign Flip SD3.5 Demo") as demo:
|
|
| 215 |
with gr.Row():
|
| 216 |
vsf_out = gr.Image(label="VSF Generated Image")
|
| 217 |
nag_out = gr.Image(label="NAG Generated Image")
|
|
|
|
| 218 |
|
| 219 |
btn = gr.Button("Generate")
|
| 220 |
-
btn.click(fn=generate_video, inputs=[pos, neg, guidance, bias, step, seed, nag_guidance, nag_alpha, nag_tau, nag_step], outputs=[vsf_out, nag_out])
|
| 221 |
-
|
| 222 |
|
| 223 |
|
| 224 |
demo.launch(share=True)
|
|
|
|
| 56 |
every=1
|
| 57 |
)
|
| 58 |
|
| 59 |
+
def save_image(prompt: str, negative_prompt: str, img_vsf: Image, img_nag: Image, img_normal: Image, parameters: dict) -> None:
|
| 60 |
vsf_image_path = IMAGE_DATASET_DIR / f"{uuid4()}_vsf.png"
|
| 61 |
nag_image_path = IMAGE_DATASET_DIR / f"{uuid4()}_nag.png"
|
| 62 |
+
normal_image_path = IMAGE_DATASET_DIR / f"{uuid4()}_normal.png"
|
| 63 |
|
| 64 |
with scheduler.lock:
|
| 65 |
img_vsf.save(vsf_image_path)
|
| 66 |
img_nag.save(nag_image_path)
|
| 67 |
+
img_normal.save(normal_image_path)
|
| 68 |
with IMAGE_JSONL_PATH.open("a") as f:
|
| 69 |
+
json.dump({"prompt": prompt, "negative_prompt": negative_prompt, "vsf_image_path": str(vsf_image_path), "nag_image_path": str(nag_image_path), "normal_image_path": str(normal_image_path), "parameters": parameters, "timestamp": datetime.utcnow().isoformat()}, f)
|
| 70 |
+
f.write("\n")
|
| 71 |
|
| 72 |
|
| 73 |
pipe = pipe.to("cuda")
|
|
|
|
| 106 |
).images[0]
|
| 107 |
nag_path = f"images/{uuid.uuid4().hex}_nag.png"
|
| 108 |
output_nag.save(nag_path)
|
| 109 |
+
|
| 110 |
+
output_normal = nag_pipe(
|
| 111 |
+
prompt=positive_prompt,
|
| 112 |
+
negative_prompt=negative_prompt,
|
| 113 |
+
num_inference_steps=nag_step,
|
| 114 |
+
nag_scale=0.0,
|
| 115 |
+
guidance_scale=0.0,
|
| 116 |
+
).images[0]
|
| 117 |
+
normal_path = f"images/{uuid.uuid4().hex}_normal.png"
|
| 118 |
+
output_normal.save(normal_path)
|
| 119 |
+
|
| 120 |
print(f"NAG Image saved to {nag_path}")
|
| 121 |
+
save_image(positive_prompt, negative_prompt, output, output_nag, output_normal, {
|
| 122 |
"guidance_scale": guidance_scale,
|
| 123 |
"bias": bias,
|
| 124 |
"step": step,
|
|
|
|
| 128 |
"nag_tau": nag_tau,
|
| 129 |
"nag_step": nag_step,
|
| 130 |
})
|
| 131 |
+
return output_path, nag_path, normal_path
|
| 132 |
|
| 133 |
import json
|
| 134 |
with open("sample_prompts.json", "r") as f:
|
|
|
|
| 228 |
with gr.Row():
|
| 229 |
vsf_out = gr.Image(label="VSF Generated Image")
|
| 230 |
nag_out = gr.Image(label="NAG Generated Image")
|
| 231 |
+
normal_out = gr.Image(label="Without Negative Guidance")
|
| 232 |
|
| 233 |
btn = gr.Button("Generate")
|
| 234 |
+
btn.click(fn=generate_video, inputs=[pos, neg, guidance, bias, step, seed, nag_guidance, nag_alpha, nag_tau, nag_step], outputs=[vsf_out, nag_out, normal_out])
|
|
|
|
| 235 |
|
| 236 |
|
| 237 |
demo.launch(share=True)
|