Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,6 @@ else:
|
|
41 |
|
42 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16).to(device)
|
43 |
pipe.load_lora_weights(default_lora, weight_name = default_weight_name) # default load lora
|
44 |
-
pipe.fuse_lora(lora_scale=0.9)
|
45 |
|
46 |
def scrape_lora_link(url):
|
47 |
try:
|
@@ -65,7 +64,7 @@ def scrape_lora_link(url):
|
|
65 |
except requests.RequestException as e:
|
66 |
raise gr.Error(f"An error occurred while fetching the URL: {e}")
|
67 |
|
68 |
-
def enable_lora(
|
69 |
pipe.unload_lora_weights()
|
70 |
if not lora_add:
|
71 |
gr.Info("No Lora Loaded, Use basemodel")
|
@@ -76,13 +75,11 @@ def enable_lora(lora_scale,lora_add,progress=gr.Progress(track_tqdm=True)):
|
|
76 |
if lora_name:
|
77 |
print(f'lora loading: {lora_add}/{lora_name}')
|
78 |
pipe.load_lora_weights(lora_add, weight_name=lora_name)
|
79 |
-
pipe.fuse_lora(lora_scale=lora_scale)
|
80 |
gr.Info(f"{lora_add} Loaded")
|
81 |
return gr.update(label="LoRA Loaded Now")
|
82 |
else:
|
83 |
try:
|
84 |
pipe.load_lora_weights(lora_add)
|
85 |
-
pipe.fuse_lora(lora_scale=lora_scale)
|
86 |
gr.Info(f"{lora_add} Loaded")
|
87 |
return gr.update(label="LoRA Loaded Now")
|
88 |
except:
|
@@ -92,6 +89,7 @@ def enable_lora(lora_scale,lora_add,progress=gr.Progress(track_tqdm=True)):
|
|
92 |
def generate_image(
|
93 |
prompt:str,
|
94 |
lora_word:str,
|
|
|
95 |
width:int=768,
|
96 |
height:int=1024,
|
97 |
scales:float=3.5,
|
@@ -106,7 +104,8 @@ def generate_image(
|
|
106 |
seed = random.randint(0, MAX_SEED)
|
107 |
seed = int(seed)
|
108 |
|
109 |
-
|
|
|
110 |
|
111 |
print(f"Prompt: {text}")
|
112 |
|
@@ -122,6 +121,7 @@ def generate_image(
|
|
122 |
max_sequence_length=512,
|
123 |
num_images_per_prompt=nums,
|
124 |
generator=generator,
|
|
|
125 |
).images
|
126 |
|
127 |
return image, seed
|
@@ -218,7 +218,7 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
218 |
examples_per_page=4,
|
219 |
)
|
220 |
|
221 |
-
load_lora.click(fn=enable_lora, inputs=[
|
222 |
|
223 |
gr.on(
|
224 |
triggers=[
|
@@ -229,6 +229,7 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
229 |
inputs=[
|
230 |
prompt,
|
231 |
lora_word,
|
|
|
232 |
width,
|
233 |
height,
|
234 |
scales,
|
|
|
41 |
|
42 |
pipe = FluxPipeline.from_pretrained(model, torch_dtype=torch.bfloat16).to(device)
|
43 |
pipe.load_lora_weights(default_lora, weight_name = default_weight_name) # default load lora
|
|
|
44 |
|
45 |
def scrape_lora_link(url):
|
46 |
try:
|
|
|
64 |
except requests.RequestException as e:
|
65 |
raise gr.Error(f"An error occurred while fetching the URL: {e}")
|
66 |
|
67 |
+
def enable_lora(lora_add,progress=gr.Progress(track_tqdm=True)):
|
68 |
pipe.unload_lora_weights()
|
69 |
if not lora_add:
|
70 |
gr.Info("No Lora Loaded, Use basemodel")
|
|
|
75 |
if lora_name:
|
76 |
print(f'lora loading: {lora_add}/{lora_name}')
|
77 |
pipe.load_lora_weights(lora_add, weight_name=lora_name)
|
|
|
78 |
gr.Info(f"{lora_add} Loaded")
|
79 |
return gr.update(label="LoRA Loaded Now")
|
80 |
else:
|
81 |
try:
|
82 |
pipe.load_lora_weights(lora_add)
|
|
|
83 |
gr.Info(f"{lora_add} Loaded")
|
84 |
return gr.update(label="LoRA Loaded Now")
|
85 |
except:
|
|
|
89 |
def generate_image(
|
90 |
prompt:str,
|
91 |
lora_word:str,
|
92 |
+
lora_scale:float=0.0,
|
93 |
width:int=768,
|
94 |
height:int=1024,
|
95 |
scales:float=3.5,
|
|
|
104 |
seed = random.randint(0, MAX_SEED)
|
105 |
seed = int(seed)
|
106 |
|
107 |
+
prompt = str(translator.translate(prompt, 'English'))
|
108 |
+
text = f"{prompt} {lora_word}"
|
109 |
|
110 |
print(f"Prompt: {text}")
|
111 |
|
|
|
121 |
max_sequence_length=512,
|
122 |
num_images_per_prompt=nums,
|
123 |
generator=generator,
|
124 |
+
joint_attention_kwargs={"scale": lora_scale},
|
125 |
).images
|
126 |
|
127 |
return image, seed
|
|
|
218 |
examples_per_page=4,
|
219 |
)
|
220 |
|
221 |
+
load_lora.click(fn=enable_lora, inputs=[lora_add], outputs=lora_add)
|
222 |
|
223 |
gr.on(
|
224 |
triggers=[
|
|
|
229 |
inputs=[
|
230 |
prompt,
|
231 |
lora_word,
|
232 |
+
lora_scale,
|
233 |
width,
|
234 |
height,
|
235 |
scales,
|