Surn commited on
Commit
69421e3
·
1 Parent(s): ee02840

Add object removal now that fill works - bad keys

Browse files
app.py CHANGED
@@ -118,7 +118,7 @@ from utils.version_info import (
118
  #from utils.depth_estimation import (get_depth_map_from_state)
119
 
120
  input_image_palette = []
121
- current_prerendered_image = gr.State("./images/Beeuty-1.png")
122
  user_dir = constants.TMPDIR
123
  lora_models = get_lora_models()
124
  selected_index = gr.State(value=-1)
@@ -509,7 +509,7 @@ def generate_image_lowmem(
509
  #del conditions
510
  del generator
511
  # Move the pipeline and clear cache
512
- pipe.to("cpu")
513
  torch.cuda.empty_cache()
514
  torch.cuda.ipc_collect()
515
  print(torch.cuda.memory_summary(device=None, abbreviated=False))
@@ -1187,27 +1187,16 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1187
  image_mode="RGBA",
1188
  format="PNG",
1189
  brush=gr.Brush(colors=['#000000', '#3270cc', '#cc3232', '#32cc70', '#ffffff']),
1190
- canvas_size=(640,360)
1191
  )
1192
  with gr.Row():
1193
  with gr.Column(scale=1):
1194
  sketch_replace_input_image_button = gr.Button("Replace Input Image with sketch", elem_id="sketch_replace_input_image_button", elem_classes="solid")
1195
  sketch_alpha_composite_slider = gr.Slider(0,100,50,0.5, label="Sketch Transparancy", elem_id="alpha_composite_slider")
1196
  btn_sketch_alpha_composite = gr.Button("Overlay Sketch on Input Image", elem_id="btn_sketchninput", elem_classes="solid")
1197
- gr.Markdown("### Do Not add to image if using a fill model. <span style='color: red; font-style: bolder;'>Click the pencil to start drawing.</span>")
1198
 
1199
  with gr.Column(scale=1):
1200
- with gr.Accordion("Hex Coloring and Exclusion", open = False):
1201
- with gr.Row():
1202
- with gr.Column():
1203
- color_picker = gr.ColorPicker(label="Pick a color to exclude",value="#505050")
1204
- with gr.Column():
1205
- filter_color = gr.Checkbox(label="Filter Excluded Colors from Sampling", value=False,)
1206
- fill_hex = gr.Checkbox(label="Fill Hex with color from Image", value=True)
1207
- exclude_color_button = gr.Button("Exclude Color", elem_id="exlude_color_button", elem_classes="solid")
1208
- color_display = gr.DataFrame(label="List of Excluded RGBA Colors", headers=["R", "G", "B", "A"], elem_id="excluded_colors", type="array", value=build_dataframe(excluded_color_list), interactive=True, elem_classes="solid centered")
1209
- selected_row = gr.Number(0, label="Selected Row", visible=False)
1210
- delete_button = gr.Button("Delete Row", elem_id="delete_exclusion_button", elem_classes="solid")
1211
  with gr.Accordion("Image Filters", open = False):
1212
  with gr.Row():
1213
  with gr.Column():
@@ -1366,19 +1355,31 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty',
1366
  with gr.Row():
1367
  image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", info="applies to Input, Sketch and Template Image",minimum=0, maximum=1.0, value=0.85, step=0.01, interactive=True)
1368
  with gr.Accordion("Advanced Hexagon Settings", open = False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1369
  with gr.Row():
1370
- start_x = gr.Number(label="Start X", value=20, minimum=-512, maximum= 512, precision=0)
1371
- start_y = gr.Number(label="Start Y", value=20, minimum=-512, maximum= 512, precision=0)
1372
- end_x = gr.Number(label="End X", value=-20, minimum=-512, maximum= 512, precision=0)
1373
- end_y = gr.Number(label="End Y", value=-20, minimum=-512, maximum= 512, precision=0)
1374
  with gr.Row():
 
1375
  x_spacing = gr.Number(label="Adjust Horizontal spacing", value=-10, minimum=-200, maximum=200, precision=1)
1376
  y_spacing = gr.Number(label="Adjust Vertical spacing", value=3, minimum=-200, maximum=200, precision=1)
1377
- with gr.Row():
1378
- rotation = gr.Slider(-90, 180, 0.0, 0.1, label="Hexagon Rotation (degree)")
1379
- sides = gr.Dropdown(label="Grid Shapes", info="other choices do not form grids",choices=["triangle", "square", "hexagon"], value="hexagon")
1380
- add_hex_text = gr.Dropdown(label="Add Text to Hexagons", choices=[None, "Column-Row Coordinates", "Column(Letter)-Row Coordinates", "Column-Row(Letter) Coordinates", "Sequential Numbers", "Playing Cards Sequential", "Playing Cards Alternate Red and Black", "Custom List"], value=None)
1381
- with gr.Row():
1382
  custom_text_list = gr.TextArea(label="Custom Text List", value=constants.cards_alternating, visible=False,)
1383
  custom_text_color_list = gr.TextArea(label="Custom Text Color List", value=constants.card_colors_alternating, visible=False)
1384
  with gr.Row():
 
118
  #from utils.depth_estimation import (get_depth_map_from_state)
119
 
120
  input_image_palette = []
121
+ current_prerendered_image = gr.State("./images/images/Bee-test-2.png")
122
  user_dir = constants.TMPDIR
123
  lora_models = get_lora_models()
124
  selected_index = gr.State(value=-1)
 
509
  #del conditions
510
  del generator
511
  # Move the pipeline and clear cache
512
+ #pipe.to("cpu")
513
  torch.cuda.empty_cache()
514
  torch.cuda.ipc_collect()
515
  print(torch.cuda.memory_summary(device=None, abbreviated=False))
 
1187
  image_mode="RGBA",
1188
  format="PNG",
1189
  brush=gr.Brush(colors=['#000000', '#3270cc', '#cc3232', '#32cc70', '#ffffff']),
1190
+ canvas_size=(640,480)
1191
  )
1192
  with gr.Row():
1193
  with gr.Column(scale=1):
1194
  sketch_replace_input_image_button = gr.Button("Replace Input Image with sketch", elem_id="sketch_replace_input_image_button", elem_classes="solid")
1195
  sketch_alpha_composite_slider = gr.Slider(0,100,50,0.5, label="Sketch Transparancy", elem_id="alpha_composite_slider")
1196
  btn_sketch_alpha_composite = gr.Button("Overlay Sketch on Input Image", elem_id="btn_sketchninput", elem_classes="solid")
1197
+ gr.Markdown("### Do Not add to image if using a fill model. Black is replaced by fill model. <span style='color: red; font-style: bolder;'>Click the pencil to start drawing.</span>")
1198
 
1199
  with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
 
1200
  with gr.Accordion("Image Filters", open = False):
1201
  with gr.Row():
1202
  with gr.Column():
 
1355
  with gr.Row():
1356
  image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", info="applies to Input, Sketch and Template Image",minimum=0, maximum=1.0, value=0.85, step=0.01, interactive=True)
1357
  with gr.Accordion("Advanced Hexagon Settings", open = False):
1358
+ with gr.Accordion("Hex Coloring and Exclusion", open = True):
1359
+ with gr.Row():
1360
+ with gr.Column():
1361
+ color_picker = gr.ColorPicker(label="Pick a color to exclude",value="#505050")
1362
+ with gr.Column():
1363
+ filter_color = gr.Checkbox(label="Filter Excluded Colors from Sampling", value=False,)
1364
+ fill_hex = gr.Checkbox(label="Fill Hex with color from Image", value=True)
1365
+ exclude_color_button = gr.Button("Exclude Color", elem_id="exlude_color_button", elem_classes="solid")
1366
+ color_display = gr.DataFrame(label="List of Excluded RGBA Colors", headers=["R", "G", "B", "A"], elem_id="excluded_colors", type="array", value=build_dataframe(excluded_color_list), interactive=True, elem_classes="solid centered")
1367
+ selected_row = gr.Number(0, label="Selected Row", visible=False)
1368
+ delete_button = gr.Button("Delete Row", elem_id="delete_exclusion_button", elem_classes="solid")
1369
+ with gr.Accordion("Hex Grid Location on Image", open = False):
1370
+ with gr.Row():
1371
+ start_x = gr.Number(label="Start X", value=20, minimum=-512, maximum= 512, precision=0)
1372
+ start_y = gr.Number(label="Start Y", value=20, minimum=-512, maximum= 512, precision=0)
1373
+ end_x = gr.Number(label="End X", value=-20, minimum=-512, maximum= 512, precision=0)
1374
+ end_y = gr.Number(label="End Y", value=-20, minimum=-512, maximum= 512, precision=0)
1375
  with gr.Row():
1376
+ rotation = gr.Slider(-90, 180, 0.0, 0.1, label="Hexagon Rotation (degree)")
1377
+ sides = gr.Dropdown(label="Grid Shapes", info="The shapes that form grids",choices=["triangle", "square", "hexagon"], value="hexagon")
 
 
1378
  with gr.Row():
1379
+ add_hex_text = gr.Dropdown(label="Add Text to Hexagons", choices=[None, "Column-Row Coordinates", "Column(Letter)-Row Coordinates", "Column-Row(Letter) Coordinates", "Sequential Numbers", "Playing Cards Sequential", "Playing Cards Alternate Red and Black", "Custom List"], value=None)
1380
  x_spacing = gr.Number(label="Adjust Horizontal spacing", value=-10, minimum=-200, maximum=200, precision=1)
1381
  y_spacing = gr.Number(label="Adjust Vertical spacing", value=3, minimum=-200, maximum=200, precision=1)
1382
+ with gr.Row():
 
 
 
 
1383
  custom_text_list = gr.TextArea(label="Custom Text List", value=constants.cards_alternating, visible=False,)
1384
  custom_text_color_list = gr.TextArea(label="Custom Text Color List", value=constants.card_colors_alternating, visible=False)
1385
  with gr.Row():
images/prerendered/th/object_removal.png ADDED

Git LFS Details

  • SHA256: 4e6f65d9aac99f149d6ec6c4f2394678edb12cbf15d62f53f7c7d12ca3cb3760
  • Pointer size: 131 Bytes
  • Size of remote file: 880 kB
utils/constants.py CHANGED
@@ -69,7 +69,7 @@ os.makedirs(TMPDIR, exist_ok=True)
69
 
70
 
71
  PROMPTS = {
72
- "Mecha Wasteland Arena": "Regional overhead view, directly from above, centered on the map, of a Mecha battlefield map. post-industrial wasteland with crumbling structures, volcanic ridges, scrapyards, and ash plains. Features elevated overwatch positions for long-range combat and tight brawling areas for close-quarters engagements. Colors: rusted red, charcoal gray, muted orange, ash white, dark brown. Partial edge hexes are black.",
73
  "BorderBlack": "Planetary overhead view, directly from above, centered on the planet’s surface, of a hexagon-based alien world map with black borders. Features rivers, mountains, volcanoes, and polar snow regions. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black.",
74
  "Earth": "Planetary overhead view, directly from above, centered on the planet’s surface, of an Earth-like world map with rivers, mountains, volcanoes, and polar snow regions. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black.",
75
  "Beeuty": "Regional overhead view, directly from above, centered on the map, of a tabletop gaming map with honeycomb-shaped terrain, lakes, dense forests, magical flora, and hex grids. Designed for clarity and strategic gameplay. Colors: yellow, green, purple, brown. Partial edge hexes are black.",
@@ -225,6 +225,7 @@ LORA_WEIGHTS = [
225
  "SebastianBodza/flux_cute3D",
226
  "gokaygokay/Flux-Seamless-Texture-LoRA",
227
  "gokaygokay/Flux-Game-Assets-LoRA-v2",
 
228
  ]
229
 
230
  # Map each LoRA weight to its corresponding model
@@ -243,6 +244,7 @@ LORA_TO_MODEL = {
243
  "SebastianBodza/flux_cute3D":"black-forest-labs/FLUX.1-dev",
244
  "gokaygokay/Flux-Seamless-Texture-LoRA":"black-forest-labs/FLUX.1-dev",
245
  "gokaygokay/Flux-Game-Assets-LoRA-v2":"black-forest-labs/FLUX.1-dev",
 
246
  }
247
  condition_type = ["depth", "canny", "subject", "coloring", "deblurring", "fill", "redux"]
248
 
@@ -361,7 +363,7 @@ LORA_DETAILS = {
361
  "thumbnail": "https://huggingface.co/VideoAditor/Flux-Lora-Realism/resolve/main/images/feel-the-difference-between-using-flux-with-lora-from-xlab-v0-j0ehybmvxehd1.png",
362
  "show_in_gallery": True
363
  }
364
- ],
365
  "Cossale/Frames2-Flex.1": [
366
  {
367
  "weight_name": "backdrops_v2.safetensors",
@@ -559,7 +561,29 @@ LORA_DETAILS = {
559
  "thumbnail": "https://huggingface.co/gokaygokay/Flux-Game-Assets-LoRA-v2/resolve/main/images/example_y2bqpuphc.png",
560
  "show_in_gallery": True
561
  }
562
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  }
564
 
565
  def sort_loras(sortby):
@@ -587,8 +611,10 @@ def sort_loras(sortby):
587
  # Default title to key if not provided
588
  if not lora_info["title"]:
589
  lora_info["title"] = key
590
- # Only add to gallery if there is an image set or any item is flagged "show_in_gallery"
591
- if lora_info["image"] or any(item.get("show_in_gallery", False) for item in details):
 
 
592
  loras.append(lora_info)
593
  # Add models from the MODELS list with a default thumbnail
594
  for model in MODELS:
 
69
 
70
 
71
  PROMPTS = {
72
+ "Mecha Wasteland Arena": "Regional overhead view, directly from above, centered on the map, of a Mecha battlefield map. post-industrial wasteland with crumbling structures, volcanic ridges, scrapyards, and ash plains. Features elevated overwatch positions for long-range combat and tight brawling areas for close-quarters engagements. Partial edge hexes are black. Colors: red, gray, muted orange, ash white, dark brown.",
73
  "BorderBlack": "Planetary overhead view, directly from above, centered on the planet’s surface, of a hexagon-based alien world map with black borders. Features rivers, mountains, volcanoes, and polar snow regions. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black.",
74
  "Earth": "Planetary overhead view, directly from above, centered on the planet’s surface, of an Earth-like world map with rivers, mountains, volcanoes, and polar snow regions. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black.",
75
  "Beeuty": "Regional overhead view, directly from above, centered on the map, of a tabletop gaming map with honeycomb-shaped terrain, lakes, dense forests, magical flora, and hex grids. Designed for clarity and strategic gameplay. Colors: yellow, green, purple, brown. Partial edge hexes are black.",
 
225
  "SebastianBodza/flux_cute3D",
226
  "gokaygokay/Flux-Seamless-Texture-LoRA",
227
  "gokaygokay/Flux-Game-Assets-LoRA-v2",
228
+ "lrzjason/ObjectRemovalFluxFill",
229
  ]
230
 
231
  # Map each LoRA weight to its corresponding model
 
244
  "SebastianBodza/flux_cute3D":"black-forest-labs/FLUX.1-dev",
245
  "gokaygokay/Flux-Seamless-Texture-LoRA":"black-forest-labs/FLUX.1-dev",
246
  "gokaygokay/Flux-Game-Assets-LoRA-v2":"black-forest-labs/FLUX.1-dev",
247
+ "lrzjason/ObjectRemovalFluxFill":"black-forest-labs/FLUX.1-Fill-dev",
248
  }
249
  condition_type = ["depth", "canny", "subject", "coloring", "deblurring", "fill", "redux"]
250
 
 
363
  "thumbnail": "https://huggingface.co/VideoAditor/Flux-Lora-Realism/resolve/main/images/feel-the-difference-between-using-flux-with-lora-from-xlab-v0-j0ehybmvxehd1.png",
364
  "show_in_gallery": True
365
  }
366
+ ],
367
  "Cossale/Frames2-Flex.1": [
368
  {
369
  "weight_name": "backdrops_v2.safetensors",
 
561
  "thumbnail": "https://huggingface.co/gokaygokay/Flux-Game-Assets-LoRA-v2/resolve/main/images/example_y2bqpuphc.png",
562
  "show_in_gallery": True
563
  }
564
+ ],
565
+ "lrzjason/ObjectRemovalFluxFill":[
566
+ {
567
+ "notes": "Used to remove objects, may leave a blur "
568
+ },
569
+ {
570
+ "weight_name": "objectRemovalv1_r32.safetensors",
571
+ },
572
+ {
573
+ "title": "Object Removal",
574
+ },
575
+ {
576
+ "parameters" :{
577
+ "guidance_scale": "30",
578
+ "num_inference_steps": "50",
579
+ "max_sequence_length": "512"
580
+ }
581
+ },
582
+ {
583
+ "thumbnail": "images/prerendered/th/object_removal.png",
584
+ "show_in_gallery": False
585
+ }
586
+ ],
587
  }
588
 
589
  def sort_loras(sortby):
 
611
  # Default title to key if not provided
612
  if not lora_info["title"]:
613
  lora_info["title"] = key
614
+ # Only add to gallery if flagged "show_in_gallery" = True
615
+ if any(item.get("show_in_gallery", False) for item in details):
616
+ if lora_info["image"] == "":
617
+ lora_info["image"] = "images/Beeuty-1.png"
618
  loras.append(lora_info)
619
  # Add models from the MODELS list with a default thumbnail
620
  for model in MODELS:
utils/image_utils.py CHANGED
@@ -10,7 +10,7 @@ from typing import List, Union, is_typeddict
10
  #import numpy as np
11
  #import math
12
  from pathlib import Path
13
- from utils.constants import default_lut_example_img, PRE_RENDERED_MAPS_JSON_LEVELS
14
  from utils.color_utils import (
15
  detect_color_format,
16
  update_color_opacity
@@ -18,8 +18,6 @@ from utils.color_utils import (
18
  from utils.file_utils import rename_file_to_lowercase_extension, get_file_parts
19
 
20
 
21
-
22
-
23
  def save_image_to_temp_png(image_source, user_dir: str = None, file_name: str = None):
24
  """
25
  Opens an image from a file path, URL, or DataURL and saves it as a PNG in the user's temporary directory.
@@ -1310,19 +1308,19 @@ def calculate_optimal_fill_dimensions(image: Image.Image):
1310
  height = FIXED_DIMENSION
1311
  width = round(FIXED_DIMENSION * original_aspect_ratio)
1312
 
1313
- # Ensure dimensions are multiples of 8
1314
- width = (width // 8) * 8
1315
- height = (height // 8) * 8
1316
 
1317
  # Enforce aspect ratio limits
1318
  calculated_aspect_ratio = width / height
1319
  if calculated_aspect_ratio > MAX_ASPECT_RATIO:
1320
- width = (height * MAX_ASPECT_RATIO // 8) * 8
1321
  elif calculated_aspect_ratio < MIN_ASPECT_RATIO:
1322
- height = (width / MIN_ASPECT_RATIO // 8) * 8
1323
 
1324
  # Ensure width and height remain above the minimum dimensions
1325
- width = max(width, 576) if width == FIXED_DIMENSION else width
1326
- height = max(height, 576) if height == FIXED_DIMENSION else height
1327
 
1328
  return width, height
 
10
  #import numpy as np
11
  #import math
12
  from pathlib import Path
13
+ from utils.constants import default_lut_example_img, PRE_RENDERED_MAPS_JSON_LEVELS, BASE_HEIGHT
14
  from utils.color_utils import (
15
  detect_color_format,
16
  update_color_opacity
 
18
  from utils.file_utils import rename_file_to_lowercase_extension, get_file_parts
19
 
20
 
 
 
21
  def save_image_to_temp_png(image_source, user_dir: str = None, file_name: str = None):
22
  """
23
  Opens an image from a file path, URL, or DataURL and saves it as a PNG in the user's temporary directory.
 
1308
  height = FIXED_DIMENSION
1309
  width = round(FIXED_DIMENSION * original_aspect_ratio)
1310
 
1311
+ # Ensure dimensions are multiples of 16
1312
+ width = (width // 16) * 16
1313
+ height = (height // 16) * 16
1314
 
1315
  # Enforce aspect ratio limits
1316
  calculated_aspect_ratio = width / height
1317
  if calculated_aspect_ratio > MAX_ASPECT_RATIO:
1318
+ width = (height * MAX_ASPECT_RATIO // 16) * 16
1319
  elif calculated_aspect_ratio < MIN_ASPECT_RATIO:
1320
+ height = (width / MIN_ASPECT_RATIO // 16) * 16
1321
 
1322
  # Ensure width and height remain above the minimum dimensions
1323
+ width = max(width, BASE_HEIGHT) if width == FIXED_DIMENSION else width
1324
+ height = max(height, BASE_HEIGHT) if height == FIXED_DIMENSION else height
1325
 
1326
  return width, height
utils/lora_details.py CHANGED
@@ -107,7 +107,7 @@ def approximate_token_count(prompt):
107
  """
108
  words = prompt.split()
109
  # Average tokens per word (can vary based on language and model)
110
- tokens_per_word = 1.3
111
  return int(len(words) * tokens_per_word)
112
 
113
  def split_prompt_by_tokens(prompt, token_number):
@@ -131,7 +131,7 @@ def split_prompt_precisely(prompt, max_tokens=77, model="gpt-3.5-turbo"):
131
  return prompt, ""
132
 
133
  # Find the split point
134
- split_point = max_tokens
135
  split_tokens = tokens[:split_point]
136
  remaining_tokens = tokens[split_point:]
137
 
 
107
  """
108
  words = prompt.split()
109
  # Average tokens per word (can vary based on language and model)
110
+ tokens_per_word = 1.35
111
  return int(len(words) * tokens_per_word)
112
 
113
  def split_prompt_by_tokens(prompt, token_number):
 
131
  return prompt, ""
132
 
133
  # Find the split point
134
+ split_point = max_tokens - 1
135
  split_tokens = tokens[:split_point]
136
  remaining_tokens = tokens[split_point:]
137