Himanshu-AT commited on
Commit
6f47450
·
1 Parent(s): c6696f9

add controlImage

Browse files
Files changed (2) hide show
  1. app.py +13 -6
  2. requirements.txt +1 -0
app.py CHANGED
@@ -3,23 +3,27 @@ import numpy as np
3
 
4
  import spaces
5
  import torch
6
- import spaces
7
  import random
 
8
 
9
  from diffusers import FluxFillPipeline
10
  from PIL import Image
11
 
 
 
 
 
 
 
12
 
13
  MAX_SEED = np.iinfo(np.int32).max
14
  MAX_IMAGE_SIZE = 2048
15
 
16
  pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
17
  pipe.load_lora_weights("alvdansen/flux-koda")
18
- # pipe.enable_sequential_cpu_offload()
19
- # pipe.enable_fp16()
20
  pipe.enable_lora()
21
- # pipe.vae.enable_slicing()
22
- # pipe.vae.enable_tiling()
23
 
24
  def calculate_optimal_dimensions(image: Image.Image):
25
  # Extract the original dimensions
@@ -67,7 +71,10 @@ def infer(edit_images, prompt, seed=42, randomize_seed=False, width=1024, height
67
  mask = edit_images["layers"][0]
68
  if randomize_seed:
69
  seed = random.randint(0, MAX_SEED)
 
 
70
  image = pipe(
 
71
  prompt=prompt,
72
  image=image,
73
  mask_image=mask,
@@ -183,4 +190,4 @@ with gr.Blocks(css=css) as demo:
183
  outputs = [result, seed]
184
  )
185
 
186
- demo.launch()
 
3
 
4
  import spaces
5
  import torch
 
6
  import random
7
+ from image_gen_aux import DepthPreprocessor
8
 
9
  from diffusers import FluxFillPipeline
10
  from PIL import Image
11
 
12
+ def remove_background(image):
13
+ # Placeholder function for background removal
14
+ # Use a library or model like Inspyrenet for actual implementation
15
+ mask = generate_mask(image)
16
+ subject = apply_mask(image, mask)
17
+ return subject, mask
18
 
19
  MAX_SEED = np.iinfo(np.int32).max
20
  MAX_IMAGE_SIZE = 2048
21
 
22
  pipe = FluxFillPipeline.from_pretrained("black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16).to("cuda")
23
  pipe.load_lora_weights("alvdansen/flux-koda")
 
 
24
  pipe.enable_lora()
25
+
26
+ processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
27
 
28
  def calculate_optimal_dimensions(image: Image.Image):
29
  # Extract the original dimensions
 
71
  mask = edit_images["layers"][0]
72
  if randomize_seed:
73
  seed = random.randint(0, MAX_SEED)
74
+
75
+ controlImage = processor(image)[0].convert("RGB")
76
  image = pipe(
77
+ control_image=controlImage,
78
  prompt=prompt,
79
  image=image,
80
  mask_image=mask,
 
190
  outputs = [result, seed]
191
  )
192
 
193
+ demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  git+https://github.com/huggingface/diffusers.git
2
  transformers
3
  accelerate
 
1
+ git+https://github.com/asomoza/image_gen_aux.git
2
  git+https://github.com/huggingface/diffusers.git
3
  transformers
4
  accelerate