Ashoka74 commited on
Commit
43ecd1c
ยท
verified ยท
1 Parent(s): 2e90656

Update merged_app2.py

Browse files
Files changed (1) hide show
  1. merged_app2.py +101 -97
merged_app2.py CHANGED
@@ -116,7 +116,7 @@ model_path3 = './checkpoints/sam2_hiera_large.pt'
116
  model_path4 = './checkpoints/config.json'
117
  model_path5 = './checkpoints/preprocessor_config.json'
118
  model_path6 = './configs/sam2_hiera_l.yaml'
119
- model_path7 = './mvadapter_i2mv_sdxl.safetensors'
120
 
121
  # Base URL for the repository
122
  BASE_URL = 'https://huggingface.co/Ashoka74/Placement/resolve/main/'
@@ -129,7 +129,7 @@ model_urls = {
129
  model_path4: 'config.json',
130
  model_path5: 'preprocessor_config.json',
131
  model_path6: 'sam2_hiera_l.yaml',
132
- model_path7: 'mvadapter_i2mv_sdxl.safetensors'
133
  }
134
 
135
  # Ensure directories exist
@@ -153,13 +153,13 @@ ensure_directories()
153
  download_models()
154
 
155
 
156
- hf_hub_download(repo_id="black-forest-labs/FLUX.1-Redux-dev", filename="flux1-redux-dev.safetensors", local_dir="models/style_models")
157
- hf_hub_download(repo_id="black-forest-labs/FLUX.1-Depth-dev", filename="flux1-depth-dev.safetensors", local_dir="models/diffusion_models")
158
- hf_hub_download(repo_id="Comfy-Org/sigclip_vision_384", filename="sigclip_vision_patch14_384.safetensors", local_dir="models/clip_vision")
159
- hf_hub_download(repo_id="Kijai/DepthAnythingV2-safetensors", filename="depth_anything_v2_vitl_fp32.safetensors", local_dir="models/depthanything")
160
- hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev", filename="ae.safetensors", local_dir="models/vae/FLUX1")
161
- hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="clip_l.safetensors", local_dir="models/text_encoders")
162
- t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp16.safetensors", local_dir="models/text_encoders/t5")
163
 
164
 
165
  sd15_name = 'stablediffusionapi/realistic-vision-v51'
@@ -759,7 +759,9 @@ def process(input_fg, prompt, image_width, image_height, num_samples, seed, step
759
  input_height, input_width = input_fg.shape[:2]
760
 
761
  bg_source = BGSource(bg_source)
762
-
 
 
763
  if bg_source == BGSource.UPLOAD:
764
  pass
765
  elif bg_source == BGSource.UPLOAD_FLIP:
@@ -1373,8 +1375,8 @@ def add_extra_model_paths() -> None:
1373
  print("Could not find the extra_model_paths config file.")
1374
 
1375
  # Initialize paths
1376
- add_comfyui_directory_to_sys_path()
1377
- add_extra_model_paths()
1378
 
1379
  def import_custom_nodes() -> None:
1380
  import asyncio
@@ -1388,91 +1390,93 @@ def import_custom_nodes() -> None:
1388
  init_extra_nodes()
1389
 
1390
  # Import all necessary nodes
1391
- from nodes import (
1392
- StyleModelLoader,
1393
- VAEEncode,
1394
- NODE_CLASS_MAPPINGS,
1395
- LoadImage,
1396
- CLIPVisionLoader,
1397
- SaveImage,
1398
- VAELoader,
1399
- CLIPVisionEncode,
1400
- DualCLIPLoader,
1401
- EmptyLatentImage,
1402
- VAEDecode,
1403
- UNETLoader,
1404
- CLIPTextEncode,
1405
- )
1406
 
1407
  # Initialize all constant nodes and models in global context
1408
- import_custom_nodes()
1409
 
1410
  # Global variables for preloaded models and constants
1411
  #with torch.inference_mode():
1412
  # Initialize constants
1413
- intconstant = NODE_CLASS_MAPPINGS["INTConstant"]()
1414
- CONST_1024 = intconstant.get_value(value=1024)
1415
-
1416
- # Load CLIP
1417
- dualcliploader = DualCLIPLoader()
1418
- CLIP_MODEL = dualcliploader.load_clip(
1419
- clip_name1="t5/t5xxl_fp16.safetensors",
1420
- clip_name2="clip_l.safetensors",
1421
- type="flux",
1422
- )
1423
-
1424
- # Load VAE
1425
- vaeloader = VAELoader()
1426
- VAE_MODEL = vaeloader.load_vae(vae_name="FLUX1/ae.safetensors")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1427
 
1428
- # Load UNET
1429
- unetloader = UNETLoader()
1430
- UNET_MODEL = unetloader.load_unet(
1431
- unet_name="flux1-depth-dev.safetensors", weight_dtype="default"
1432
- )
1433
-
1434
- # Load CLIP Vision
1435
- clipvisionloader = CLIPVisionLoader()
1436
- CLIP_VISION_MODEL = clipvisionloader.load_clip(
1437
- clip_name="sigclip_vision_patch14_384.safetensors"
1438
- )
1439
-
1440
- # Load Style Model
1441
- stylemodelloader = StyleModelLoader()
1442
- STYLE_MODEL = stylemodelloader.load_style_model(
1443
- style_model_name="flux1-redux-dev.safetensors"
1444
- )
1445
-
1446
- # Initialize samplers
1447
- ksamplerselect = NODE_CLASS_MAPPINGS["KSamplerSelect"]()
1448
- SAMPLER = ksamplerselect.get_sampler(sampler_name="euler")
1449
-
1450
- # Initialize depth model
1451
- cr_clip_input_switch = NODE_CLASS_MAPPINGS["CR Clip Input Switch"]()
1452
- downloadandloaddepthanythingv2model = NODE_CLASS_MAPPINGS["DownloadAndLoadDepthAnythingV2Model"]()
1453
- DEPTH_MODEL = downloadandloaddepthanythingv2model.loadmodel(
1454
- model="depth_anything_v2_vitl_fp32.safetensors"
1455
- )
1456
- cliptextencode = CLIPTextEncode()
1457
- loadimage = LoadImage()
1458
- vaeencode = VAEEncode()
1459
- fluxguidance = NODE_CLASS_MAPPINGS["FluxGuidance"]()
1460
- instructpixtopixconditioning = NODE_CLASS_MAPPINGS["InstructPixToPixConditioning"]()
1461
- clipvisionencode = CLIPVisionEncode()
1462
- stylemodelapplyadvanced = NODE_CLASS_MAPPINGS["StyleModelApplyAdvanced"]()
1463
- emptylatentimage = EmptyLatentImage()
1464
- basicguider = NODE_CLASS_MAPPINGS["BasicGuider"]()
1465
- basicscheduler = NODE_CLASS_MAPPINGS["BasicScheduler"]()
1466
- randomnoise = NODE_CLASS_MAPPINGS["RandomNoise"]()
1467
- samplercustomadvanced = NODE_CLASS_MAPPINGS["SamplerCustomAdvanced"]()
1468
- vaedecode = VAEDecode()
1469
- cr_text = NODE_CLASS_MAPPINGS["CR Text"]()
1470
- saveimage = SaveImage()
1471
- getimagesizeandcount = NODE_CLASS_MAPPINGS["GetImageSizeAndCount"]()
1472
- depthanything_v2 = NODE_CLASS_MAPPINGS["DepthAnything_V2"]()
1473
- imageresize = NODE_CLASS_MAPPINGS["ImageResize+"]()
1474
 
1475
  @spaces.GPU
 
1476
  def generate_image(prompt, structure_image, style_image, depth_strength=15, style_strength=0.5, progress=gr.Progress(track_tqdm=True)) -> str:
1477
  """Main generation function that processes inputs and returns the path to the generated image."""
1478
 
@@ -1672,10 +1676,10 @@ with gr.Blocks() as app:
1672
  with gr.Group():
1673
  gr.Markdown("Outpaint")
1674
  with gr.Row():
1675
- with gr.Column(scale=2):
1676
- prompt_fill = gr.Textbox(label="Prompt (Optional)")
1677
- with gr.Column(scale=1):
1678
- fill_button = gr.Button("Generate")
1679
  target_ratio = gr.Radio(
1680
  label="Image Ratio",
1681
  choices=["9:16", "16:9", "1:1", "Custom"],
@@ -1850,9 +1854,9 @@ with gr.Blocks() as app:
1850
  ).then(
1851
  fn=inpaint,
1852
  inputs=[dummy_image_for_outputs, width_slider, height_slider, overlap_percentage, num_inference_steps,
1853
- resize_option, custom_resize_percentage, prompt_fill, alignment_dropdown,
1854
  overlap_left, overlap_right, overlap_top, overlap_bottom],
1855
- outputs=[fill_result]).then(clear_memory, inputs=[], outputs=[])
1856
  # ).then(
1857
  # fn=lambda: gr.update(visible=True),
1858
  # inputs=None,
@@ -1866,9 +1870,9 @@ with gr.Blocks() as app:
1866
  ).then(
1867
  fn=inpaint,
1868
  inputs=[dummy_image_for_outputs, width_slider, height_slider, overlap_percentage, num_inference_steps,
1869
- resize_option, custom_resize_percentage, prompt_fill, alignment_dropdown,
1870
  overlap_left, overlap_right, overlap_top, overlap_bottom],
1871
- outputs=[fill_result]).then(clear_memory, inputs=[], outputs=[])
1872
 
1873
  def convert_to_pil(image):
1874
  try:
@@ -1905,7 +1909,7 @@ with gr.Blocks() as app:
1905
  outputs=[extracted_fg, x_slider, y_slider]
1906
  ).then(clear_memory, inputs=[], outputs=[])
1907
 
1908
- with gr.Tab("Style Transfer"):
1909
  gr.Markdown("## Apply the style of an image to another one")
1910
  with gr.Row():
1911
  with gr.Column():
 
116
  model_path4 = './checkpoints/config.json'
117
  model_path5 = './checkpoints/preprocessor_config.json'
118
  model_path6 = './configs/sam2_hiera_l.yaml'
119
+ #model_path7 = './mvadapter_i2mv_sdxl.safetensors'
120
 
121
  # Base URL for the repository
122
  BASE_URL = 'https://huggingface.co/Ashoka74/Placement/resolve/main/'
 
129
  model_path4: 'config.json',
130
  model_path5: 'preprocessor_config.json',
131
  model_path6: 'sam2_hiera_l.yaml',
132
+ # model_path7: 'mvadapter_i2mv_sdxl.safetensors'
133
  }
134
 
135
  # Ensure directories exist
 
153
  download_models()
154
 
155
 
156
+ # hf_hub_download(repo_id="black-forest-labs/FLUX.1-Redux-dev", filename="flux1-redux-dev.safetensors", local_dir="models/style_models")
157
+ # hf_hub_download(repo_id="black-forest-labs/FLUX.1-Depth-dev", filename="flux1-depth-dev.safetensors", local_dir="models/diffusion_models")
158
+ # hf_hub_download(repo_id="Comfy-Org/sigclip_vision_384", filename="sigclip_vision_patch14_384.safetensors", local_dir="models/clip_vision")
159
+ # hf_hub_download(repo_id="Kijai/DepthAnythingV2-safetensors", filename="depth_anything_v2_vitl_fp32.safetensors", local_dir="models/depthanything")
160
+ # hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev", filename="ae.safetensors", local_dir="models/vae/FLUX1")
161
+ # hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="clip_l.safetensors", local_dir="models/text_encoders")
162
+ # t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp16.safetensors", local_dir="models/text_encoders/t5")
163
 
164
 
165
  sd15_name = 'stablediffusionapi/realistic-vision-v51'
 
759
  input_height, input_width = input_fg.shape[:2]
760
 
761
  bg_source = BGSource(bg_source)
762
+
763
+ if bg_source == BGSource.NONE:
764
+ pass
765
  if bg_source == BGSource.UPLOAD:
766
  pass
767
  elif bg_source == BGSource.UPLOAD_FLIP:
 
1375
  print("Could not find the extra_model_paths config file.")
1376
 
1377
  # Initialize paths
1378
+ # add_comfyui_directory_to_sys_path()
1379
+ # add_extra_model_paths()
1380
 
1381
  def import_custom_nodes() -> None:
1382
  import asyncio
 
1390
  init_extra_nodes()
1391
 
1392
  # Import all necessary nodes
1393
+ # from nodes import (
1394
+ # StyleModelLoader,
1395
+ # VAEEncode,
1396
+ # NODE_CLASS_MAPPINGS,
1397
+ # LoadImage,
1398
+ # CLIPVisionLoader,
1399
+ # SaveImage,
1400
+ # VAELoader,
1401
+ # CLIPVisionEncode,
1402
+ # DualCLIPLoader,
1403
+ # EmptyLatentImage,
1404
+ # VAEDecode,
1405
+ # UNETLoader,
1406
+ # CLIPTextEncode,
1407
+ # )
1408
 
1409
  # Initialize all constant nodes and models in global context
1410
+ # import_custom_nodes()
1411
 
1412
  # Global variables for preloaded models and constants
1413
  #with torch.inference_mode():
1414
  # Initialize constants
1415
+ # intconstant = NODE_CLASS_MAPPINGS["INTConstant"]()
1416
+ # CONST_1024 = intconstant.get_value(value=1024)
1417
+
1418
+ # # Load CLIP
1419
+ # dualcliploader = DualCLIPLoader()
1420
+ # CLIP_MODEL = dualcliploader.load_clip(
1421
+ # clip_name1="t5/t5xxl_fp16.safetensors",
1422
+ # clip_name2="clip_l.safetensors",
1423
+ # type="flux",
1424
+ # )
1425
+
1426
+ # # Load VAE
1427
+ # vaeloader = VAELoader()
1428
+ # VAE_MODEL = vaeloader.load_vae(vae_name="FLUX1/ae.safetensors")
1429
+
1430
+ # # Load UNET
1431
+ # unetloader = UNETLoader()
1432
+ # UNET_MODEL = unetloader.load_unet(
1433
+ # unet_name="flux1-depth-dev.safetensors", weight_dtype="default"
1434
+ # )
1435
+
1436
+ # # Load CLIP Vision
1437
+ # clipvisionloader = CLIPVisionLoader()
1438
+ # CLIP_VISION_MODEL = clipvisionloader.load_clip(
1439
+ # clip_name="sigclip_vision_patch14_384.safetensors"
1440
+ # )
1441
+
1442
+ # # Load Style Model
1443
+ # stylemodelloader = StyleModelLoader()
1444
+ # STYLE_MODEL = stylemodelloader.load_style_model(
1445
+ # style_model_name="flux1-redux-dev.safetensors"
1446
+ # )
1447
+
1448
+ # # Initialize samplers
1449
+ # ksamplerselect = NODE_CLASS_MAPPINGS["KSamplerSelect"]()
1450
+ # SAMPLER = ksamplerselect.get_sampler(sampler_name="euler")
1451
+
1452
+ # # Initialize depth model
1453
+ # cr_clip_input_switch = NODE_CLASS_MAPPINGS["CR Clip Input Switch"]()
1454
+ # downloadandloaddepthanythingv2model = NODE_CLASS_MAPPINGS["DownloadAndLoadDepthAnythingV2Model"]()
1455
+ # DEPTH_MODEL = downloadandloaddepthanythingv2model.loadmodel(
1456
+ # model="depth_anything_v2_vitl_fp32.safetensors"
1457
+ # )
1458
+ # cliptextencode = CLIPTextEncode()
1459
+ # loadimage = LoadImage()
1460
+ # vaeencode = VAEEncode()
1461
+ # fluxguidance = NODE_CLASS_MAPPINGS["FluxGuidance"]()
1462
+ # instructpixtopixconditioning = NODE_CLASS_MAPPINGS["InstructPixToPixConditioning"]()
1463
+ # clipvisionencode = CLIPVisionEncode()
1464
+ # stylemodelapplyadvanced = NODE_CLASS_MAPPINGS["StyleModelApplyAdvanced"]()
1465
+ # emptylatentimage = EmptyLatentImage()
1466
+ # basicguider = NODE_CLASS_MAPPINGS["BasicGuider"]()
1467
+ # basicscheduler = NODE_CLASS_MAPPINGS["BasicScheduler"]()
1468
+ # randomnoise = NODE_CLASS_MAPPINGS["RandomNoise"]()
1469
+ # samplercustomadvanced = NODE_CLASS_MAPPINGS["SamplerCustomAdvanced"]()
1470
+ # vaedecode = VAEDecode()
1471
+ # cr_text = NODE_CLASS_MAPPINGS["CR Text"]()
1472
+ # saveimage = SaveImage()
1473
+ # getimagesizeandcount = NODE_CLASS_MAPPINGS["GetImageSizeAndCount"]()
1474
+ # depthanything_v2 = NODE_CLASS_MAPPINGS["DepthAnything_V2"]()
1475
+ # imageresize = NODE_CLASS_MAPPINGS["ImageResize+"]()
1476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1477
 
1478
  @spaces.GPU
1479
+ @torch.inference_mode
1480
  def generate_image(prompt, structure_image, style_image, depth_strength=15, style_strength=0.5, progress=gr.Progress(track_tqdm=True)) -> str:
1481
  """Main generation function that processes inputs and returns the path to the generated image."""
1482
 
 
1676
  with gr.Group():
1677
  gr.Markdown("Outpaint")
1678
  with gr.Row():
1679
+ # with gr.Column(scale=2):
1680
+ # # prompt_fill = gr.Textbox(label="Prompt (Optional)")
1681
+ # with gr.Column(scale=1):
1682
+ fill_button = gr.Button("Generate")
1683
  target_ratio = gr.Radio(
1684
  label="Image Ratio",
1685
  choices=["9:16", "16:9", "1:1", "Custom"],
 
1854
  ).then(
1855
  fn=inpaint,
1856
  inputs=[dummy_image_for_outputs, width_slider, height_slider, overlap_percentage, num_inference_steps,
1857
+ resize_option, custom_resize_percentage, prompt, alignment_dropdown,
1858
  overlap_left, overlap_right, overlap_top, overlap_bottom],
1859
+ outputs=[fill_result])#.then(clear_memory, inputs=[], outputs=[])
1860
  # ).then(
1861
  # fn=lambda: gr.update(visible=True),
1862
  # inputs=None,
 
1870
  ).then(
1871
  fn=inpaint,
1872
  inputs=[dummy_image_for_outputs, width_slider, height_slider, overlap_percentage, num_inference_steps,
1873
+ resize_option, custom_resize_percentage, prompt, alignment_dropdown,
1874
  overlap_left, overlap_right, overlap_top, overlap_bottom],
1875
+ outputs=[fill_result])#.then(clear_memory, inputs=[], outputs=[])
1876
 
1877
  def convert_to_pil(image):
1878
  try:
 
1909
  outputs=[extracted_fg, x_slider, y_slider]
1910
  ).then(clear_memory, inputs=[], outputs=[])
1911
 
1912
+ with gr.Tab("Style Transfer", visible=False):
1913
  gr.Markdown("## Apply the style of an image to another one")
1914
  with gr.Row():
1915
  with gr.Column():