Spaces:
Runtime error
Runtime error
Commit
·
ae0e195
1
Parent(s):
1e5a7d5
use flux canny lora
Browse files- app.py +18 -4
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -15,8 +15,12 @@ subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
|
|
| 15 |
# Load FLUX image generator
|
| 16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
model_repo_id = "black-forest-labs/FLUX.1-schnell" # Replace to the model you would like to use
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
if torch.cuda.is_available():
|
| 22 |
torch_dtype = torch.float16
|
|
@@ -25,7 +29,10 @@ else:
|
|
| 25 |
|
| 26 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 27 |
pipe = pipe.to(device)
|
| 28 |
-
pipe.load_lora_weights(
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
MAX_SEED = np.iinfo(np.int32).max
|
| 31 |
MAX_IMAGE_SIZE = 1024
|
|
@@ -94,15 +101,22 @@ def generate_description_fn(
|
|
| 94 |
)
|
| 95 |
|
| 96 |
prompt = chat_completion.choices[0].message.content + " In the style of FLTSKC"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
image = pipe(
|
| 99 |
prompt=prompt,
|
|
|
|
| 100 |
guidance_scale=0.,
|
| 101 |
num_inference_steps=4,
|
| 102 |
width=1420,
|
| 103 |
height=1080,
|
| 104 |
max_sequence_length=256,
|
| 105 |
-
|
| 106 |
).images[0]
|
| 107 |
|
| 108 |
return prompt, image
|
|
|
|
| 15 |
# Load FLUX image generator
|
| 16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
model_repo_id = "black-forest-labs/FLUX.1-schnell" # Replace to the model you would like to use
|
| 18 |
+
flat_lora_path = "matteomarjanovic/flatsketcher"
|
| 19 |
+
canny_lora_path = "black-forest-labs/FLUX.1-Canny-dev-lora"
|
| 20 |
+
flat_weigths_file = "lora.safetensors"
|
| 21 |
+
canny_weigths_file = "flux1-canny-dev-lora.safetensors"
|
| 22 |
+
|
| 23 |
+
processor = CannyDetector()
|
| 24 |
|
| 25 |
if torch.cuda.is_available():
|
| 26 |
torch_dtype = torch.float16
|
|
|
|
| 29 |
|
| 30 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
| 31 |
pipe = pipe.to(device)
|
| 32 |
+
pipe.load_lora_weights(flat_lora_path, weight_name=flat_weigths_file, adapter_name="flat")
|
| 33 |
+
pipe.load_lora_weights(canny_lora_path, weight_name=cannyweigths_file, adapter_name="canny")
|
| 34 |
+
|
| 35 |
+
pipe.set_adapters(["flat", "canny"], adapter_weights=[0.7, 0.7])
|
| 36 |
|
| 37 |
MAX_SEED = np.iinfo(np.int32).max
|
| 38 |
MAX_IMAGE_SIZE = 1024
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
prompt = chat_completion.choices[0].message.content + " In the style of FLTSKC"
|
| 104 |
+
control_image = processor(
|
| 105 |
+
image,
|
| 106 |
+
low_threshold=50,
|
| 107 |
+
high_threshold=200,
|
| 108 |
+
detect_resolution=1024,
|
| 109 |
+
image_resolution=1024
|
| 110 |
+
)
|
| 111 |
|
| 112 |
image = pipe(
|
| 113 |
prompt=prompt,
|
| 114 |
+
control_image=control_image
|
| 115 |
guidance_scale=0.,
|
| 116 |
num_inference_steps=4,
|
| 117 |
width=1420,
|
| 118 |
height=1080,
|
| 119 |
max_sequence_length=256,
|
|
|
|
| 120 |
).images[0]
|
| 121 |
|
| 122 |
return prompt, image
|
requirements.txt
CHANGED
|
@@ -6,4 +6,5 @@ transformers
|
|
| 6 |
xformers
|
| 7 |
sentencepiece
|
| 8 |
peft
|
| 9 |
-
groq
|
|
|
|
|
|
| 6 |
xformers
|
| 7 |
sentencepiece
|
| 8 |
peft
|
| 9 |
+
groq
|
| 10 |
+
controlnet-aux
|