Spaces:
Sleeping
Sleeping
Commit
•
72cad74
1
Parent(s):
2238903
attempt to load lora on cpu
Browse files
app.py
CHANGED
@@ -49,6 +49,20 @@ def update_selection(evt: gr.SelectData):
|
|
49 |
)
|
50 |
|
51 |
@spaces.GPU(duration=80)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
53 |
if selected_index is None:
|
54 |
raise gr.Error("You must select a LoRA before proceeding.")
|
@@ -69,24 +83,11 @@ def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, wid
|
|
69 |
if randomize_seed:
|
70 |
seed = random.randint(0, MAX_SEED)
|
71 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
72 |
-
|
73 |
-
with calculateDuration("Generating image"):
|
74 |
-
# Generate image
|
75 |
-
image = pipe(
|
76 |
-
prompt=f"{prompt} {trigger_word}",
|
77 |
-
num_inference_steps=steps,
|
78 |
-
guidance_scale=cfg_scale,
|
79 |
-
width=width,
|
80 |
-
height=height,
|
81 |
-
generator=generator,
|
82 |
-
joint_attention_kwargs={"scale": lora_scale},
|
83 |
-
).images[0]
|
84 |
-
|
85 |
-
yield image, seed
|
86 |
-
|
87 |
-
with calculateDuration("Unloading weights"):
|
88 |
-
pipe.unload_lora_weights()
|
89 |
|
|
|
|
|
|
|
|
|
90 |
|
91 |
css = '''
|
92 |
#gen_btn{height: 100%}
|
|
|
49 |
)
|
50 |
|
51 |
@spaces.GPU(duration=80)
|
52 |
+
def generate_image(prompt, trigger_word, steps, cfg_scale, width, height, generator, lora_scale, progress):
|
53 |
+
with calculateDuration("Generating image"):
|
54 |
+
# Generate image
|
55 |
+
image = pipe(
|
56 |
+
prompt=f"{prompt} {trigger_word}",
|
57 |
+
num_inference_steps=steps,
|
58 |
+
guidance_scale=cfg_scale,
|
59 |
+
width=width,
|
60 |
+
height=height,
|
61 |
+
generator=generator,
|
62 |
+
joint_attention_kwargs={"scale": lora_scale},
|
63 |
+
).images[0]
|
64 |
+
return image
|
65 |
+
|
66 |
def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
67 |
if selected_index is None:
|
68 |
raise gr.Error("You must select a LoRA before proceeding.")
|
|
|
83 |
if randomize_seed:
|
84 |
seed = random.randint(0, MAX_SEED)
|
85 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
image = generate_image(prompt, trigger_word, steps, cfg_scale, width, height, generator, lora_scale, progress)
|
88 |
+
|
89 |
+
pipe.unload_lora_weights()
|
90 |
+
return image, seed
|
91 |
|
92 |
css = '''
|
93 |
#gen_btn{height: 100%}
|