Spaces:
Running
on
A10G
Running
on
A10G
keep pipes in cpu until using them
Browse files
app.py
CHANGED
|
@@ -35,9 +35,9 @@ if device == "cuda":
|
|
| 35 |
|
| 36 |
scheduler_class = MyEulerAncestralDiscreteScheduler
|
| 37 |
|
| 38 |
-
pipe_inversion = SDXLDDIMPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 39 |
pipe_inference = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo",
|
| 40 |
-
use_safetensors=True)
|
| 41 |
pipe_inference.scheduler = scheduler_class.from_config(pipe_inference.scheduler.config)
|
| 42 |
pipe_inversion.scheduler = scheduler_class.from_config(pipe_inversion.scheduler.config)
|
| 43 |
pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.scheduler.config)
|
|
@@ -92,11 +92,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 92 |
# @spaces.GPU
|
| 93 |
def set_pipe(inversion_state, input_image, description_prompt, edit_guidance_scale, num_inference_steps=4,
|
| 94 |
num_inversion_steps=4, inversion_max_step=0.6, rnri_iterations=2, rnri_alpha=0.1, rnri_lr=0.2):
|
| 95 |
-
if device == 'cuda':
|
| 96 |
-
# if image_editor is not None:
|
| 97 |
-
# image_editor = image_editor.to('cpu')
|
| 98 |
-
|
| 99 |
-
torch.cuda.empty_cache()
|
| 100 |
|
| 101 |
if input_image is None or not description_prompt:
|
| 102 |
return None, "Please set all inputs."
|
|
@@ -113,8 +108,17 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 113 |
num_inversion_steps=num_inversion_steps,
|
| 114 |
edit_guidance_scale=edit_guidance_scale,
|
| 115 |
inversion_max_step=inversion_max_step)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
inversion_state = ImageEditorDemo.invert(pipe_inversion, input_image, description_prompt, config,
|
| 117 |
[rnri_iterations, rnri_alpha, rnri_lr], device)
|
|
|
|
|
|
|
|
|
|
| 118 |
return inversion_state, "Input has set!"
|
| 119 |
|
| 120 |
|
|
@@ -122,6 +126,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 122 |
def edit1(editor, target_prompt):
|
| 123 |
if editor is None:
|
| 124 |
raise gr.Error("Set inputs before editing.")
|
|
|
|
| 125 |
# if device == "cuda":
|
| 126 |
# image = editor.to(device).edit(target_prompt)
|
| 127 |
# else:
|
|
@@ -136,8 +141,16 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 136 |
# if device == "cuda":
|
| 137 |
# image = editor.to(device).edit(target_prompt)
|
| 138 |
# else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
image = ImageEditorDemo.edit(pipe_inference, target_prompt, inversion_state['latent'], inversion_state['noise'],
|
| 140 |
inversion_state['cfg'], inversion_state['cfg'].edit_guidance_scale)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
return image
|
| 142 |
|
| 143 |
|
|
|
|
| 35 |
|
| 36 |
scheduler_class = MyEulerAncestralDiscreteScheduler
|
| 37 |
|
| 38 |
+
pipe_inversion = SDXLDDIMPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)#.to(device)
|
| 39 |
pipe_inference = AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo",
|
| 40 |
+
use_safetensors=True)#.to(device)
|
| 41 |
pipe_inference.scheduler = scheduler_class.from_config(pipe_inference.scheduler.config)
|
| 42 |
pipe_inversion.scheduler = scheduler_class.from_config(pipe_inversion.scheduler.config)
|
| 43 |
pipe_inversion.scheduler_inference = scheduler_class.from_config(pipe_inference.scheduler.config)
|
|
|
|
| 92 |
# @spaces.GPU
|
| 93 |
def set_pipe(inversion_state, input_image, description_prompt, edit_guidance_scale, num_inference_steps=4,
|
| 94 |
num_inversion_steps=4, inversion_max_step=0.6, rnri_iterations=2, rnri_alpha=0.1, rnri_lr=0.2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
if input_image is None or not description_prompt:
|
| 97 |
return None, "Please set all inputs."
|
|
|
|
| 108 |
num_inversion_steps=num_inversion_steps,
|
| 109 |
edit_guidance_scale=edit_guidance_scale,
|
| 110 |
inversion_max_step=inversion_max_step)
|
| 111 |
+
if device == 'cuda':
|
| 112 |
+
torch.cuda.empty_cache()
|
| 113 |
+
pipe_inversion = pipe_inversion.to(device)
|
| 114 |
+
# if image_editor is not None:
|
| 115 |
+
# image_editor = image_editor.to('cpu')
|
| 116 |
+
|
| 117 |
inversion_state = ImageEditorDemo.invert(pipe_inversion, input_image, description_prompt, config,
|
| 118 |
[rnri_iterations, rnri_alpha, rnri_lr], device)
|
| 119 |
+
if device == 'cuda':
|
| 120 |
+
torch.cuda.empty_cache()
|
| 121 |
+
pipe_inversion = pipe_inversion.to('cpu')
|
| 122 |
return inversion_state, "Input has set!"
|
| 123 |
|
| 124 |
|
|
|
|
| 126 |
def edit1(editor, target_prompt):
|
| 127 |
if editor is None:
|
| 128 |
raise gr.Error("Set inputs before editing.")
|
| 129 |
+
|
| 130 |
# if device == "cuda":
|
| 131 |
# image = editor.to(device).edit(target_prompt)
|
| 132 |
# else:
|
|
|
|
| 141 |
# if device == "cuda":
|
| 142 |
# image = editor.to(device).edit(target_prompt)
|
| 143 |
# else:
|
| 144 |
+
|
| 145 |
+
if device == 'cuda':
|
| 146 |
+
torch.cuda.empty_cache()
|
| 147 |
+
pipe_inference = pipe_inference.to(device)
|
| 148 |
image = ImageEditorDemo.edit(pipe_inference, target_prompt, inversion_state['latent'], inversion_state['noise'],
|
| 149 |
inversion_state['cfg'], inversion_state['cfg'].edit_guidance_scale)
|
| 150 |
+
|
| 151 |
+
if device == 'cuda':
|
| 152 |
+
pipe_inference = pipe_inference.to('cpu')
|
| 153 |
+
torch.cuda.empty_cache()
|
| 154 |
return image
|
| 155 |
|
| 156 |
|