Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ import spaces
|
|
12 |
import torch
|
13 |
from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler
|
14 |
from huggingface_hub import hf_hub_download
|
|
|
15 |
|
16 |
DESCRIPTION = """
|
17 |
# Res-Adapter :Domain Consistent Resolution Adapter for Diffusion Models
|
@@ -28,7 +29,7 @@ USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE") == "1"
|
|
28 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD") == "1"
|
29 |
|
30 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
31 |
-
pipe = AutoPipelineForText2Image.from_pretrained('
|
32 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
|
33 |
|
34 |
|
@@ -75,8 +76,7 @@ def generate(
|
|
75 |
prompt_2 = None # type: ignore
|
76 |
if not use_negative_prompt_2:
|
77 |
negative_prompt_2 = None # type: ignore
|
78 |
-
|
79 |
-
base_image = pipe(
|
80 |
prompt=prompt,
|
81 |
negative_prompt=negative_prompt,
|
82 |
prompt_2=prompt_2,
|
@@ -86,11 +86,11 @@ def generate(
|
|
86 |
guidance_scale=guidance_scale_base,
|
87 |
num_inference_steps=num_inference_steps_base,
|
88 |
generator=generator,
|
89 |
-
output_type="pil"
|
|
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
res_adapt=pipe(
|
94 |
prompt=prompt,
|
95 |
negative_prompt=negative_prompt,
|
96 |
prompt_2=prompt_2,
|
@@ -100,9 +100,12 @@ def generate(
|
|
100 |
guidance_scale=guidance_scale_base,
|
101 |
num_inference_steps=num_inference_steps_base,
|
102 |
generator=generator,
|
103 |
-
output_type="pil"
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
106 |
|
107 |
|
108 |
examples = [
|
@@ -129,7 +132,7 @@ with gr.Blocks(css="footer{display:none !important}", theme=theme) as demo:
|
|
129 |
placeholder="Enter your prompt",
|
130 |
)
|
131 |
run_button = gr.Button("Generate")
|
132 |
-
# result = gr.Gallery(label="
|
133 |
with gr.Accordion("Advanced options", open=False):
|
134 |
with gr.Row():
|
135 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
|
@@ -250,7 +253,7 @@ with gr.Blocks(css="footer{display:none !important}", theme=theme) as demo:
|
|
250 |
guidance_scale_base,
|
251 |
num_inference_steps_base,
|
252 |
],
|
253 |
-
outputs=gr.Gallery(label="
|
254 |
api_name="run",
|
255 |
)
|
256 |
|
|
|
12 |
import torch
|
13 |
from diffusers import AutoPipelineForText2Image, DPMSolverMultistepScheduler
|
14 |
from huggingface_hub import hf_hub_download
|
15 |
+
from diffusers.models.attention_processor import AttnProcessor2_0
|
16 |
|
17 |
DESCRIPTION = """
|
18 |
# Res-Adapter :Domain Consistent Resolution Adapter for Diffusion Models
|
|
|
29 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD") == "1"
|
30 |
|
31 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
32 |
+
pipe = AutoPipelineForText2Image.from_pretrained('stabilityai/stable-diffusion-xl-base-1.0',use_safetensors=True)# torch_dtype=torch.float16, variant="safetensors")
|
33 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++")
|
34 |
|
35 |
|
|
|
76 |
prompt_2 = None # type: ignore
|
77 |
if not use_negative_prompt_2:
|
78 |
negative_prompt_2 = None # type: ignore
|
79 |
+
res_adapt=pipe(
|
|
|
80 |
prompt=prompt,
|
81 |
negative_prompt=negative_prompt,
|
82 |
prompt_2=prompt_2,
|
|
|
86 |
guidance_scale=guidance_scale_base,
|
87 |
num_inference_steps=num_inference_steps_base,
|
88 |
generator=generator,
|
89 |
+
output_type="pil",
|
90 |
+
).images[0]
|
91 |
|
92 |
+
pipe.unet.set_attn_processor(AttnProcessor2_0())
|
93 |
+
base_image = pipe(
|
|
|
94 |
prompt=prompt,
|
95 |
negative_prompt=negative_prompt,
|
96 |
prompt_2=prompt_2,
|
|
|
100 |
guidance_scale=guidance_scale_base,
|
101 |
num_inference_steps=num_inference_steps_base,
|
102 |
generator=generator,
|
103 |
+
output_type="pil").images[0]
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
return [res_adapt,base_image]
|
109 |
|
110 |
|
111 |
examples = [
|
|
|
132 |
placeholder="Enter your prompt",
|
133 |
)
|
134 |
run_button = gr.Button("Generate")
|
135 |
+
# result = gr.Gallery(label="Right is Res-Adapt-LORA and Left is Base"),
|
136 |
with gr.Accordion("Advanced options", open=False):
|
137 |
with gr.Row():
|
138 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
|
|
|
253 |
guidance_scale_base,
|
254 |
num_inference_steps_base,
|
255 |
],
|
256 |
+
outputs=gr.Gallery(label="Right is Res-Adapt-LORA and Left is Base"),
|
257 |
api_name="run",
|
258 |
)
|
259 |
|