jiuface commited on
Commit
5fcec1c
·
verified ·
1 Parent(s): 4ba7094

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -18,6 +18,11 @@ import boto3
18
  from io import BytesIO
19
  from datetime import datetime
20
 
 
 
 
 
 
21
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN")
23
 
@@ -27,13 +32,9 @@ login(token=HF_TOKEN)
27
  dtype = torch.bfloat16
28
  device = "cuda" if torch.cuda.is_available() else "cpu"
29
  base_model = "black-forest-labs/FLUX.1-dev"
30
-
31
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
32
-
33
  MAX_SEED = 2**32-1
34
 
35
- # pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
36
-
37
  class calculateDuration:
38
  def __init__(self, activity_name=""):
39
  self.activity_name = activity_name
@@ -86,7 +87,8 @@ def generate_image(prompt, steps, seed, cfg_scale, width, height, lora_scale, pr
86
  width=width,
87
  height=height,
88
  generator=generator,
89
- joint_attention_kwargs={"scale": lora_scale}
 
90
  ).images[0]
91
 
92
  progress(99, "Generate success!")
@@ -95,8 +97,8 @@ def generate_image(prompt, steps, seed, cfg_scale, width, height, lora_scale, pr
95
 
96
  def run_lora(prompt, cfg_scale, steps, lora_repo, lora_name, randomize_seed, seed, width, height, lora_scale, upload_to_r2, account_id, access_key, secret_key, bucket, progress=gr.Progress(track_tqdm=True)):
97
 
98
- with calculateDuration("Unloading LoRA"):
99
- pipe.unload_lora_weights()
100
 
101
  # Load LoRA weights
102
  if lora_repo and lora_name:
 
18
  from io import BytesIO
19
  from datetime import datetime
20
 
21
+ cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
22
+ os.environ["TRANSFORMERS_CACHE"] = cache_path
23
+ os.environ["HF_HUB_CACHE"] = cache_path
24
+ os.environ["HF_HOME"] = cache_path
25
+
26
 
27
  HF_TOKEN = os.environ.get("HF_TOKEN")
28
 
 
32
  dtype = torch.bfloat16
33
  device = "cuda" if torch.cuda.is_available() else "cpu"
34
  base_model = "black-forest-labs/FLUX.1-dev"
 
35
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
 
36
  MAX_SEED = 2**32-1
37
 
 
 
38
  class calculateDuration:
39
  def __init__(self, activity_name=""):
40
  self.activity_name = activity_name
 
87
  width=width,
88
  height=height,
89
  generator=generator,
90
+ joint_attention_kwargs={"scale": lora_scale},
91
+ max_sequence_length=256
92
  ).images[0]
93
 
94
  progress(99, "Generate success!")
 
97
 
98
  def run_lora(prompt, cfg_scale, steps, lora_repo, lora_name, randomize_seed, seed, width, height, lora_scale, upload_to_r2, account_id, access_key, secret_key, bucket, progress=gr.Progress(track_tqdm=True)):
99
 
100
+ # with calculateDuration("Unloading LoRA"):
101
+ # pipe.unload_lora_weights()
102
 
103
  # Load LoRA weights
104
  if lora_repo and lora_name: