Spaces:
Sleeping
Sleeping
Add seed support and update Gradio interface
Browse filesAdded a `seed` parameter to `generate_and_apply_maze_to_input` for deterministic maze generation. Updated Gradio interface with a `maze_seed` slider, adjusted default values for `maze_width` and `maze_opacity`, and included the `seed` parameter in the maze generation logic. Replaced `style_20250314.css` with `style_20260316.css` for updated styling.
- app.py +8 -6
- modules/mazlib/cli.py +6 -1
- style_20250314.css → style_20260316.css +1 -1
app.py
CHANGED
|
@@ -1198,7 +1198,7 @@ def update_maze_maker_shape_visibility(shape):
|
|
| 1198 |
)
|
| 1199 |
|
| 1200 |
|
| 1201 |
-
def generate_and_apply_maze_to_input(shape, width, height, radius, cell_size, use_iterative, show_solution, show_doors, input_image, opacity_percent):
|
| 1202 |
shape_key = (shape or "rect").lower()
|
| 1203 |
|
| 1204 |
if shape_key in ("hex", "hexagon", "hexagonal"):
|
|
@@ -1225,6 +1225,7 @@ def generate_and_apply_maze_to_input(shape, width, height, radius, cell_size, us
|
|
| 1225 |
output=maze_output_path,
|
| 1226 |
show_solution=bool(show_solution),
|
| 1227 |
show_doors=bool(show_doors),
|
|
|
|
| 1228 |
)
|
| 1229 |
temp_files.append(maze_output_path)
|
| 1230 |
except Exception as ex:
|
|
@@ -1267,7 +1268,7 @@ def getVersions():
|
|
| 1267 |
|
| 1268 |
gr.set_static_paths(paths=["images/","images/images","images/prerendered","LUT/","fonts/", "assets/"])
|
| 1269 |
title = "MapLore Magic (Development Features for HexaGrid)"
|
| 1270 |
-
with gr.Blocks(css_paths="
|
| 1271 |
with gr.Row():
|
| 1272 |
gr.Markdown("""
|
| 1273 |
# MapLore Magic (Development Features for HexaGrid)
|
|
@@ -1383,16 +1384,17 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty@=
|
|
| 1383 |
elem_classes="solid"
|
| 1384 |
)
|
| 1385 |
with gr.Row():
|
| 1386 |
-
maze_width = gr.Slider(label="Maze Width (rect/tri)", minimum=5, maximum=199, step=2, value=
|
| 1387 |
maze_height = gr.Slider(label="Maze Height (rect/tri)", minimum=5, maximum=199, step=2, value=21, interactive=True)
|
| 1388 |
maze_radius = gr.Slider(label="Hex Radius", minimum=2, maximum=40, step=1, value=8, interactive=True, visible=False)
|
| 1389 |
maze_cell_size = gr.Slider(label="Cell Size", minimum=8, maximum=80, step=1, value=20, interactive=True)
|
| 1390 |
# opacity for maze overlay when compositing onto the Input Image
|
| 1391 |
-
maze_opacity = gr.Slider(label="Maze Opacity %", minimum=0, maximum=100, value=
|
| 1392 |
with gr.Row():
|
| 1393 |
maze_use_iterative = gr.Checkbox(label="Use Iterative Generator", value=True)
|
| 1394 |
maze_show_solution = gr.Checkbox(label="Show Solution Path (red)", value=True)
|
| 1395 |
-
maze_show_doors = gr.Checkbox(label="Show Cell Outlines", value=True)
|
|
|
|
| 1396 |
maze_apply_button = gr.Button("Create Maze and Apply to Input Image", elem_classes="solid")
|
| 1397 |
maze_status = gr.Markdown(value="")
|
| 1398 |
with gr.Accordion("Sketch Pad", open = False, elem_id="sketchpd"):
|
|
@@ -1576,7 +1578,7 @@ with gr.Blocks(css_paths="style_20250314.css", title=title, theme='Surn/beeuty@=
|
|
| 1576 |
)
|
| 1577 |
maze_apply_button.click(
|
| 1578 |
fn=generate_and_apply_maze_to_input,
|
| 1579 |
-
inputs=[maze_shape, maze_width, maze_height, maze_radius, maze_cell_size, maze_use_iterative, maze_show_solution, maze_show_doors, input_image, maze_opacity],
|
| 1580 |
outputs=[input_image, maze_status],
|
| 1581 |
scroll_to_output=True,
|
| 1582 |
).then(
|
|
|
|
| 1198 |
)
|
| 1199 |
|
| 1200 |
|
| 1201 |
+
def generate_and_apply_maze_to_input(shape, width, height, radius, cell_size, use_iterative, show_solution, show_doors, input_image, opacity_percent, seed=0):
|
| 1202 |
shape_key = (shape or "rect").lower()
|
| 1203 |
|
| 1204 |
if shape_key in ("hex", "hexagon", "hexagonal"):
|
|
|
|
| 1225 |
output=maze_output_path,
|
| 1226 |
show_solution=bool(show_solution),
|
| 1227 |
show_doors=bool(show_doors),
|
| 1228 |
+
seed=int(seed) if seed is not None else 0,
|
| 1229 |
)
|
| 1230 |
temp_files.append(maze_output_path)
|
| 1231 |
except Exception as ex:
|
|
|
|
| 1268 |
|
| 1269 |
gr.set_static_paths(paths=["images/","images/images","images/prerendered","LUT/","fonts/", "assets/"])
|
| 1270 |
title = "MapLore Magic (Development Features for HexaGrid)"
|
| 1271 |
+
with gr.Blocks(css_paths="style_20260316.css", title=title, theme='Surn/beeuty@==0.5.12', delete_cache=(43200, 43200), head_paths="head.htm") as app:
|
| 1272 |
with gr.Row():
|
| 1273 |
gr.Markdown("""
|
| 1274 |
# MapLore Magic (Development Features for HexaGrid)
|
|
|
|
| 1384 |
elem_classes="solid"
|
| 1385 |
)
|
| 1386 |
with gr.Row():
|
| 1387 |
+
maze_width = gr.Slider(label="Maze Width (rect/tri)", minimum=5, maximum=199, step=2, value=37, interactive=True)
|
| 1388 |
maze_height = gr.Slider(label="Maze Height (rect/tri)", minimum=5, maximum=199, step=2, value=21, interactive=True)
|
| 1389 |
maze_radius = gr.Slider(label="Hex Radius", minimum=2, maximum=40, step=1, value=8, interactive=True, visible=False)
|
| 1390 |
maze_cell_size = gr.Slider(label="Cell Size", minimum=8, maximum=80, step=1, value=20, interactive=True)
|
| 1391 |
# opacity for maze overlay when compositing onto the Input Image
|
| 1392 |
+
maze_opacity = gr.Slider(label="Maze Opacity %", minimum=0, maximum=100, value=100, interactive=True)
|
| 1393 |
with gr.Row():
|
| 1394 |
maze_use_iterative = gr.Checkbox(label="Use Iterative Generator", value=True)
|
| 1395 |
maze_show_solution = gr.Checkbox(label="Show Solution Path (red)", value=True)
|
| 1396 |
+
maze_show_doors = gr.Checkbox(label="Show Cell Outlines", value=True)
|
| 1397 |
+
maze_seed = gr.Slider(label="Maze Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True, elem_id="maze_rnd_seed", info="0 = randomize")
|
| 1398 |
maze_apply_button = gr.Button("Create Maze and Apply to Input Image", elem_classes="solid")
|
| 1399 |
maze_status = gr.Markdown(value="")
|
| 1400 |
with gr.Accordion("Sketch Pad", open = False, elem_id="sketchpd"):
|
|
|
|
| 1578 |
)
|
| 1579 |
maze_apply_button.click(
|
| 1580 |
fn=generate_and_apply_maze_to_input,
|
| 1581 |
+
inputs=[maze_shape, maze_width, maze_height, maze_radius, maze_cell_size, maze_use_iterative, maze_show_solution, maze_show_doors, input_image, maze_opacity, maze_seed],
|
| 1582 |
outputs=[input_image, maze_status],
|
| 1583 |
scroll_to_output=True,
|
| 1584 |
).then(
|
modules/mazlib/cli.py
CHANGED
|
@@ -115,6 +115,7 @@ def main(argv=None):
|
|
| 115 |
parser.add_argument('-v', '--verbose', action='count', default=0, help='Increase verbosity (use -v or -vv)')
|
| 116 |
parser.add_argument('--show-solution', action='store_true', default=False,
|
| 117 |
help='Print path length and endpoints after solving')
|
|
|
|
| 118 |
args = parser.parse_args(argv)
|
| 119 |
|
| 120 |
# configure logging according to verbosity
|
|
@@ -181,10 +182,14 @@ def main(argv=None):
|
|
| 181 |
# hex
|
| 182 |
radius = int(size)
|
| 183 |
fname = f"maze_hex_r{radius}_{ts}.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
output_path = str(outdir / fname)
|
| 185 |
logging.info("Auto-generated output path: %s", output_path)
|
| 186 |
|
| 187 |
-
maze, path = run_maze(shape=args.shape, size=size, cell=args.cell, use_iterative=args.iterative, draw=args.draw, output=output_path, show_solution=args.show_solution)
|
| 188 |
|
| 189 |
if args.show_solution:
|
| 190 |
if not path:
|
|
|
|
| 115 |
parser.add_argument('-v', '--verbose', action='count', default=0, help='Increase verbosity (use -v or -vv)')
|
| 116 |
parser.add_argument('--show-solution', action='store_true', default=False,
|
| 117 |
help='Print path length and endpoints after solving')
|
| 118 |
+
parser.add_argument('--seed', type=int, default=0, help='Random seed (0 for random)')
|
| 119 |
args = parser.parse_args(argv)
|
| 120 |
|
| 121 |
# configure logging according to verbosity
|
|
|
|
| 182 |
# hex
|
| 183 |
radius = int(size)
|
| 184 |
fname = f"maze_hex_r{radius}_{ts}.png"
|
| 185 |
+
# append seed to filename when a non-zero seed is provided
|
| 186 |
+
if args.seed:
|
| 187 |
+
name, ext = os.path.splitext(fname)
|
| 188 |
+
fname = f"{name}_s{args.seed}{ext}"
|
| 189 |
output_path = str(outdir / fname)
|
| 190 |
logging.info("Auto-generated output path: %s", output_path)
|
| 191 |
|
| 192 |
+
maze, path = run_maze(shape=args.shape, size=size, cell=args.cell, use_iterative=args.iterative, draw=args.draw, output=output_path, show_solution=args.show_solution, seed=args.seed)
|
| 193 |
|
| 194 |
if args.show_solution:
|
| 195 |
if not path:
|
style_20250314.css → style_20260316.css
RENAMED
|
@@ -151,4 +151,4 @@ a {
|
|
| 151 |
.feather-circle, .svelte-rrog8b.medium svg {
|
| 152 |
border: 1px solid rgba(253, 224, 71, 0.375);
|
| 153 |
border-radius: 15px;
|
| 154 |
-
}
|
|
|
|
| 151 |
.feather-circle, .svelte-rrog8b.medium svg {
|
| 152 |
border: 1px solid rgba(253, 224, 71, 0.375);
|
| 153 |
border-radius: 15px;
|
| 154 |
+
}
|