Spaces:
Running
on
Zero
Running
on
Zero
Update Readme, constants and add Sketchpad
Browse files- README.md +7 -14
- app.py +63 -21
- modules/constants.py +7 -7
- modules/image_utils.py +18 -1
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: yellow
|
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
python_version: 3.10.13
|
8 |
-
sdk_version: 5.
|
9 |
app_file: app.py
|
10 |
pinned: false
|
11 |
short_description: Transform Your Images into Mesmerizing Hexagon Grids
|
@@ -13,12 +13,9 @@ license: apache-2.0
|
|
13 |
tags:
|
14 |
- map maker
|
15 |
- tabletop
|
16 |
-
- hexagon
|
17 |
- text-to-image
|
18 |
- image-generation
|
19 |
- flux
|
20 |
-
- depth
|
21 |
-
- 3d
|
22 |
hf_oauth: true
|
23 |
fullWidth: true
|
24 |
thumbnail: >-
|
@@ -27,17 +24,15 @@ thumbnail: >-
|
|
27 |
|
28 |
# Hex Game Maker
|
29 |
## Description
|
30 |
-
Welcome to Hex Game Maker, the ultimate tool for transforming your images into mesmerizing hexagon grid masterpieces!
|
|
|
31 |
|
32 |
### What Can You Do?
|
33 |
-
- **Generate Hex Game Maker:** Create stunning hexagon grid overlays on any image with fully customizable parameters.
|
34 |
- **AI-Powered Image Generation:** Use AI to generate images based on your prompts and apply hexagon grids to them.
|
35 |
-
- **
|
36 |
-
- **Interactive Customization:** Adjust hexagon size, border size, rotation, background color, and more in real-time.
|
37 |
-
- **Depth and 3D Model Generation:** Generate depth maps and 3D models from your images for enhanced visualization.
|
38 |
- **Image Filter [Look-Up Table (LUT)] Application:** Apply filters (LUTs) to your images for color grading and enhancement.
|
39 |
- **Pre-rendered Maps:** Access a library of pre-rendered hexagon maps for quick and easy customization.
|
40 |
-
|
41 |
|
42 |
### Why You'll Love It
|
43 |
- **Fun and Easy to Use:** With an intuitive interface and real-time previews, creating hexagon grids has never been this fun!
|
@@ -47,15 +42,13 @@ Welcome to Hex Game Maker, the ultimate tool for transforming your images into m
|
|
47 |
|
48 |
### Get Started
|
49 |
1. **Upload or Generate an Image:** Start by uploading your own image or generate one using our AI-powered tool.
|
50 |
-
2. **
|
51 |
-
3. **Download and Share:** Once you're happy with your creation, download it and share it with the world!
|
52 |
|
53 |
### Advanced Features
|
54 |
- **Generative AI Integration:** Utilize models like `black-forest-labs/FLUX.1-dev` and various LoRA weights for generating unique images.
|
55 |
- **Pre-rendered Maps:** Access a library of pre-rendered hexagon maps for quick and easy customization.
|
56 |
- **Image Filter [Look-Up Table (LUT)] Application:** Apply filters (LUTs) to your images for color grading and enhancement.
|
57 |
-
|
58 |
-
- **Add Margins:** Customize margins around your images for a polished finish.
|
59 |
|
60 |
Join the hive and start creating with Hex Game Maker today!
|
61 |
|
|
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
python_version: 3.10.13
|
8 |
+
sdk_version: 5.17.1
|
9 |
app_file: app.py
|
10 |
pinned: false
|
11 |
short_description: Transform Your Images into Mesmerizing Hexagon Grids
|
|
|
13 |
tags:
|
14 |
- map maker
|
15 |
- tabletop
|
|
|
16 |
- text-to-image
|
17 |
- image-generation
|
18 |
- flux
|
|
|
|
|
19 |
hf_oauth: true
|
20 |
fullWidth: true
|
21 |
thumbnail: >-
|
|
|
24 |
|
25 |
# Hex Game Maker
|
26 |
## Description
|
27 |
+
Welcome to Hex Game Maker, the ultimate tool for transforming your images into mesmerizing hexagon grid masterpieces! Well, this was a test project for HexaGrid. It has some nice features that did not make it into the final version of the program.
|
28 |
+
The intention was to do a full conversion, but the limitation on Negative Prompts is what killed this approach. It does not consistently render table top maps.. but it can do a lot!
|
29 |
|
30 |
### What Can You Do?
|
|
|
31 |
- **AI-Powered Image Generation:** Use AI to generate images based on your prompts and apply hexagon grids to them.
|
32 |
+
- **Sketch, upload or select:** images to guide your AI image generation
|
|
|
|
|
33 |
- **Image Filter [Look-Up Table (LUT)] Application:** Apply filters (LUTs) to your images for color grading and enhancement.
|
34 |
- **Pre-rendered Maps:** Access a library of pre-rendered hexagon maps for quick and easy customization.
|
35 |
+
|
36 |
|
37 |
### Why You'll Love It
|
38 |
- **Fun and Easy to Use:** With an intuitive interface and real-time previews, creating hexagon grids has never been this fun!
|
|
|
42 |
|
43 |
### Get Started
|
44 |
1. **Upload or Generate an Image:** Start by uploading your own image or generate one using our AI-powered tool.
|
45 |
+
2. **Download and Share:** Once you're happy with your creation, download it and share it with the world!
|
|
|
46 |
|
47 |
### Advanced Features
|
48 |
- **Generative AI Integration:** Utilize models like `black-forest-labs/FLUX.1-dev` and various LoRA weights for generating unique images.
|
49 |
- **Pre-rendered Maps:** Access a library of pre-rendered hexagon maps for quick and easy customization.
|
50 |
- **Image Filter [Look-Up Table (LUT)] Application:** Apply filters (LUTs) to your images for color grading and enhancement.
|
51 |
+
|
|
|
52 |
|
53 |
Join the hive and start creating with Hex Game Maker today!
|
54 |
|
app.py
CHANGED
@@ -20,7 +20,8 @@ from diffusers import (
|
|
20 |
AutoencoderKL,
|
21 |
AutoPipelineForImage2Image,
|
22 |
FluxPipeline,
|
23 |
-
FlowMatchEulerDiscreteScheduler
|
|
|
24 |
|
25 |
from huggingface_hub import (
|
26 |
hf_hub_download,
|
@@ -48,7 +49,8 @@ from modules.image_utils import (
|
|
48 |
multiply_and_blend_images,
|
49 |
alpha_composite_with_control,
|
50 |
crop_and_resize_image,
|
51 |
-
convert_to_rgba_png
|
|
|
52 |
)
|
53 |
from modules.constants import (
|
54 |
LORA_DETAILS, LORAS as loras, MODELS,
|
@@ -327,6 +329,12 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, lora_scal
|
|
327 |
flash_attention_enabled = torch.backends.cuda.flash_sdp_enabled()
|
328 |
if flash_attention_enabled:
|
329 |
pipe.attn_implementation="flash_attention_2"
|
|
|
|
|
|
|
|
|
|
|
|
|
330 |
print(f"\nGenerating image with prompt: {prompt_mash}\n")
|
331 |
approx_tokens= approximate_token_count(prompt_mash)
|
332 |
if approx_tokens > 76:
|
@@ -357,7 +365,13 @@ def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps
|
|
357 |
flash_attention_enabled = torch.backends.cuda.flash_sdp_enabled()
|
358 |
if flash_attention_enabled:
|
359 |
pipe_i2i.attn_implementation="flash_attention_2"
|
360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
print(f"\nGenerating image with prompt: {prompt_mash} and {image_input_path}\n")
|
362 |
approx_tokens= approximate_token_count(prompt_mash)
|
363 |
if approx_tokens > 76:
|
@@ -561,6 +575,11 @@ def update_prompt_visibility(map_option):
|
|
561 |
gr.update(visible=is_visible)
|
562 |
)
|
563 |
|
|
|
|
|
|
|
|
|
|
|
564 |
@spaces.GPU()
|
565 |
def getVersions():
|
566 |
return versions_html()
|
@@ -571,7 +590,7 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
571 |
with gr.Row():
|
572 |
gr.Markdown("""
|
573 |
# Hex Game Maker
|
574 |
-
## Transform Your Images into Mesmerizing
|
575 |
with gr.Row():
|
576 |
with gr.Accordion("Welcome to Hex Game Maker, the ultimate tool for transforming your images into stunning hexagon grid artworks. Whether you're a tabletop game enthusiast, a digital artist, or someone who loves unique patterns, Hex Game Maker has something for you.", open=False, elem_classes="intro"):
|
577 |
gr.Markdown ("""
|
@@ -624,9 +643,9 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
624 |
interactive=True,
|
625 |
elem_classes="centered solid imgcontainer",
|
626 |
key="imgInput",
|
627 |
-
image_mode=
|
628 |
format="PNG",
|
629 |
-
show_download_button=True
|
630 |
)
|
631 |
def on_input_image_change(image_path):
|
632 |
if image_path is None:
|
@@ -641,17 +660,30 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
641 |
outputs=[input_image], scroll_to_output=True,
|
642 |
)
|
643 |
with gr.Column(scale=0):
|
644 |
-
with gr.Accordion("
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
655 |
with gr.Accordion("Image Filters", open = False):
|
656 |
with gr.Row():
|
657 |
with gr.Column():
|
@@ -739,7 +771,7 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
739 |
)
|
740 |
|
741 |
with gr.Column(scale=1, elem_id="gen_column"):
|
742 |
-
generate_button = gr.Button("Generate From
|
743 |
with gr.Row():
|
744 |
with gr.Column(scale=0):
|
745 |
selected_info = gr.Markdown("")
|
@@ -763,13 +795,12 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
763 |
with gr.Column(scale=1):
|
764 |
# Gallery from PRE_RENDERED_IMAGES GOES HERE
|
765 |
prerendered_image_gallery = gr.Gallery(label="Image Gallery", show_label=True, value=build_prerendered_images_by_quality(3), elem_id="gallery", elem_classes="solid", type="filepath", columns=[3], rows=[3], preview=False ,object_fit="contain", height="auto", format="png",allow_preview=False)
|
766 |
-
with gr.Column(scale=1):
|
767 |
-
#image_guidance_stength = gr.Slider(label="Image Guidance Strength", minimum=0, maximum=1.0, value=0.25, step=0.01, interactive=True)
|
768 |
replace_input_image_button = gr.Button(
|
769 |
"Replace Input Image",
|
770 |
elem_id="prerendered_replace_input_image_button",
|
771 |
elem_classes="solid"
|
772 |
-
)
|
773 |
generate_input_image_from_gallery = gr.Button(
|
774 |
"Generate AI Image from Gallery",
|
775 |
elem_id="generate_input_image_from_gallery",
|
@@ -827,6 +858,17 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
827 |
outputs=gr.State(current_prerendered_image), # Update the state with the selected image
|
828 |
show_api=False, scroll_to_output=True
|
829 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
830 |
# replace input image with selected prerendered image gallery selection
|
831 |
replace_input_image_button.click(
|
832 |
lambda: current_prerendered_image.value,
|
|
|
20 |
AutoencoderKL,
|
21 |
AutoPipelineForImage2Image,
|
22 |
FluxPipeline,
|
23 |
+
FlowMatchEulerDiscreteScheduler,
|
24 |
+
DPMSolverMultistepScheduler)
|
25 |
|
26 |
from huggingface_hub import (
|
27 |
hf_hub_download,
|
|
|
49 |
multiply_and_blend_images,
|
50 |
alpha_composite_with_control,
|
51 |
crop_and_resize_image,
|
52 |
+
convert_to_rgba_png,
|
53 |
+
get_image_from_dict
|
54 |
)
|
55 |
from modules.constants import (
|
56 |
LORA_DETAILS, LORAS as loras, MODELS,
|
|
|
329 |
flash_attention_enabled = torch.backends.cuda.flash_sdp_enabled()
|
330 |
if flash_attention_enabled:
|
331 |
pipe.attn_implementation="flash_attention_2"
|
332 |
+
# Compile UNet
|
333 |
+
#pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead")
|
334 |
+
pipe.vae.enable_tiling() # For larger resolutions if needed
|
335 |
+
|
336 |
+
# Disable unnecessary features
|
337 |
+
pipe.safety_checker = None
|
338 |
print(f"\nGenerating image with prompt: {prompt_mash}\n")
|
339 |
approx_tokens= approximate_token_count(prompt_mash)
|
340 |
if approx_tokens > 76:
|
|
|
365 |
flash_attention_enabled = torch.backends.cuda.flash_sdp_enabled()
|
366 |
if flash_attention_enabled:
|
367 |
pipe_i2i.attn_implementation="flash_attention_2"
|
368 |
+
# Compile UNet
|
369 |
+
#pipe.transformer = torch.compile(pipe.transformer, mode="reduce-overhead")
|
370 |
+
pipe.vae.enable_tiling() # For larger resolutions if needed
|
371 |
+
|
372 |
+
# Disable unnecessary features
|
373 |
+
pipe.safety_checker = None
|
374 |
+
image_input = open_image(image_input_path)
|
375 |
print(f"\nGenerating image with prompt: {prompt_mash} and {image_input_path}\n")
|
376 |
approx_tokens= approximate_token_count(prompt_mash)
|
377 |
if approx_tokens > 76:
|
|
|
575 |
gr.update(visible=is_visible)
|
576 |
)
|
577 |
|
578 |
+
def replace_input_with_sketch_image(sketch_image):
|
579 |
+
print(f"Sketch Image: {sketch_image}\n")
|
580 |
+
sketch, is_dict = get_image_from_dict(sketch_image)
|
581 |
+
return sketch
|
582 |
+
|
583 |
@spaces.GPU()
|
584 |
def getVersions():
|
585 |
return versions_html()
|
|
|
590 |
with gr.Row():
|
591 |
gr.Markdown("""
|
592 |
# Hex Game Maker
|
593 |
+
## Transform Your Images into Mesmerizing Table Top Map Masterpieces! ⬢""", elem_classes="intro")
|
594 |
with gr.Row():
|
595 |
with gr.Accordion("Welcome to Hex Game Maker, the ultimate tool for transforming your images into stunning hexagon grid artworks. Whether you're a tabletop game enthusiast, a digital artist, or someone who loves unique patterns, Hex Game Maker has something for you.", open=False, elem_classes="intro"):
|
596 |
gr.Markdown ("""
|
|
|
643 |
interactive=True,
|
644 |
elem_classes="centered solid imgcontainer",
|
645 |
key="imgInput",
|
646 |
+
image_mode="RGB",
|
647 |
format="PNG",
|
648 |
+
show_download_button=True
|
649 |
)
|
650 |
def on_input_image_change(image_path):
|
651 |
if image_path is None:
|
|
|
660 |
outputs=[input_image], scroll_to_output=True,
|
661 |
)
|
662 |
with gr.Column(scale=0):
|
663 |
+
# with gr.Accordion("Sketch Pad", open = False):
|
664 |
+
# with gr.Row():
|
665 |
+
# sketch_image = gr.Sketchpad(
|
666 |
+
# label="Input Image",
|
667 |
+
# type="filepath",
|
668 |
+
# #invert_colors=True,
|
669 |
+
# #source=['upload','canvas'],
|
670 |
+
# #tool=['editor','select','color-sketch'],
|
671 |
+
# interactive=True,
|
672 |
+
# elem_classes="centered solid imgcontainer",
|
673 |
+
# key="imgInput",
|
674 |
+
# image_mode="RGB",
|
675 |
+
# format="PNG"
|
676 |
+
# )
|
677 |
+
# with gr.Row():
|
678 |
+
# with gr.Column(scale=1):
|
679 |
+
# sketch_replace_input_image_button = gr.Button(
|
680 |
+
# "Replace Input Image with sketch",
|
681 |
+
# elem_id="sketch_replace_input_image_button",
|
682 |
+
# elem_classes="solid"
|
683 |
+
# )
|
684 |
+
# with gr.Column(scale=2):
|
685 |
+
# alpha_composite_slider = gr.Slider(0,100,50,0.5, label="Alpha Composite Sketch to Input Image", elem_id="alpha_composite_slider")
|
686 |
+
|
687 |
with gr.Accordion("Image Filters", open = False):
|
688 |
with gr.Row():
|
689 |
with gr.Column():
|
|
|
771 |
)
|
772 |
|
773 |
with gr.Column(scale=1, elem_id="gen_column"):
|
774 |
+
generate_button = gr.Button("Generate From Map Options, Input Image and LoRa Style", variant="primary", elem_id="gen_btn")
|
775 |
with gr.Row():
|
776 |
with gr.Column(scale=0):
|
777 |
selected_info = gr.Markdown("")
|
|
|
795 |
with gr.Column(scale=1):
|
796 |
# Gallery from PRE_RENDERED_IMAGES GOES HERE
|
797 |
prerendered_image_gallery = gr.Gallery(label="Image Gallery", show_label=True, value=build_prerendered_images_by_quality(3), elem_id="gallery", elem_classes="solid", type="filepath", columns=[3], rows=[3], preview=False ,object_fit="contain", height="auto", format="png",allow_preview=False)
|
798 |
+
with gr.Column(scale=1):
|
|
|
799 |
replace_input_image_button = gr.Button(
|
800 |
"Replace Input Image",
|
801 |
elem_id="prerendered_replace_input_image_button",
|
802 |
elem_classes="solid"
|
803 |
+
)
|
804 |
generate_input_image_from_gallery = gr.Button(
|
805 |
"Generate AI Image from Gallery",
|
806 |
elem_id="generate_input_image_from_gallery",
|
|
|
858 |
outputs=gr.State(current_prerendered_image), # Update the state with the selected image
|
859 |
show_api=False, scroll_to_output=True
|
860 |
)
|
861 |
+
# alpha_composite_slider.change(
|
862 |
+
# fn=alpha_composite_with_control,
|
863 |
+
# inputs=[input_image, sketch_image, alpha_composite_slider],
|
864 |
+
# outputs=[input_image],
|
865 |
+
# scroll_to_output=True
|
866 |
+
# )
|
867 |
+
# sketch_replace_input_image_button.click(
|
868 |
+
# lambda sketch_image: replace_input_with_sketch_image(sketch_image),
|
869 |
+
# inputs=[sketch_image],
|
870 |
+
# outputs=[input_image], scroll_to_output=True
|
871 |
+
# )
|
872 |
# replace input image with selected prerendered image gallery selection
|
873 |
replace_input_image_button.click(
|
874 |
lambda: current_prerendered_image.value,
|
modules/constants.py
CHANGED
@@ -43,10 +43,10 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
43 |
TARGET_SIZE = (2688,1536)
|
44 |
|
45 |
PROMPTS = {
|
46 |
-
"BorderBlack": "Top-down view of a hexagon-based alien map with black borders. Features rivers, mountains, volcanoes, and snow at top and bottom. Colors: light blue, green, tan, brown. No reflections or shadows. Partial hexes on edges are black.",
|
47 |
-
"Earth": "Top-down view of a world map with rivers, mountains, volcanoes, and snow at top and bottom. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black.
|
48 |
-
"Beeuty": "Top-down view of a table map with honeycomb_shapes, lakes, dense forests, magical flora, and hex_grids. Map for tabletop gaming with clarity and strategic elements. Colors: yellow, green, purple, brown. Partial hexes on edges are black.",
|
49 |
-
"Scifi City": "Top-down view of a futuristic
|
50 |
"Alien Landscape": "Top-down view of a barren alien world map made from hexagon pieces. Features light blue rivers, brown mountains, red volcanoes, and white snow at top and bottom. Colors: light blue, green, tan, brown. Partial hexes on edges are black.",
|
51 |
"Alien World": "Top-down view of an alien world map built from hexagon pieces. Includes rivers, mountains, volcanoes, and snowy areas. Colors: light blue, green, tan, brown. Partial edge hexes are black. Overhead view.",
|
52 |
"Mystic Forest": "Top-down view of a mystic forest map with lakes, dense forests, magical flora, and hex grids. Designed for clarity in tabletop gaming. Colors: light blue, green, purple, brown. Partial hexes on edges are black.",
|
@@ -56,9 +56,9 @@ PROMPTS = {
|
|
56 |
|
57 |
NEGATIVE_PROMPTS = {
|
58 |
"BorderBlack": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
59 |
-
"Earth": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, missing
|
60 |
-
"
|
61 |
-
"
|
62 |
"Alien Landscape": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
63 |
"Alien World": "Earth, humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
64 |
"Mystic Forest": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
|
|
43 |
TARGET_SIZE = (2688,1536)
|
44 |
|
45 |
PROMPTS = {
|
46 |
+
"BorderBlack": "Top-down view, from above. of a hexagon-based alien map with black borders. Features rivers, mountains, volcanoes, and snow at top and bottom. Colors: light blue, green, tan, brown. No reflections or shadows. Partial hexes on edges are black.",
|
47 |
+
"Earth": "Top-down view of a world map with rivers, mountains, volcanoes, and snow at top and bottom. Colors: light blue, green, tan, brown. No reflections or shadows. Partial edge hexes are black. from above.",
|
48 |
+
"Beeuty": "Top-down view of a table map with honeycomb_shapes, lakes, dense forests, magical flora, and hex_grids. Map for tabletop gaming with clarity and strategic elements. Colors: yellow, green, purple, brown. Partial hexes on edges are black. Viewed from above.",
|
49 |
+
"Scifi City": "Top-down view of a futuristic urban_battlefield_map with lakes, forests, ruined_buildings, and city streets. Emphasizes clarity and strategy for tabletop games. Colors: teal, dark green, violet, brown. Partial edge hexes are black. Viewed from above.",
|
50 |
"Alien Landscape": "Top-down view of a barren alien world map made from hexagon pieces. Features light blue rivers, brown mountains, red volcanoes, and white snow at top and bottom. Colors: light blue, green, tan, brown. Partial hexes on edges are black.",
|
51 |
"Alien World": "Top-down view of an alien world map built from hexagon pieces. Includes rivers, mountains, volcanoes, and snowy areas. Colors: light blue, green, tan, brown. Partial edge hexes are black. Overhead view.",
|
52 |
"Mystic Forest": "Top-down view of a mystic forest map with lakes, dense forests, magical flora, and hex grids. Designed for clarity in tabletop gaming. Colors: light blue, green, purple, brown. Partial hexes on edges are black.",
|
|
|
56 |
|
57 |
NEGATIVE_PROMPTS = {
|
58 |
"BorderBlack": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
59 |
+
"Earth": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, missing map of the Earth, isometric",
|
60 |
+
"Beeuty": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, map of the Earth, isometric",
|
61 |
+
"Scifi City": "humans, missing_buildings, vehicles, text, logos, reflections, shadows, Earth, isometric",
|
62 |
"Alien Landscape": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
63 |
"Alien World": "Earth, humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
64 |
"Mystic Forest": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric",
|
modules/image_utils.py
CHANGED
@@ -6,7 +6,7 @@ import base64
|
|
6 |
import numpy as np
|
7 |
#from decimal import ROUND_CEILING
|
8 |
from PIL import Image, ImageChops, ImageDraw, ImageEnhance, ImageFilter, ImageDraw, ImageOps, ImageMath
|
9 |
-
from typing import List, Union
|
10 |
#import numpy as np
|
11 |
#import math
|
12 |
from pathlib import Path
|
@@ -15,6 +15,18 @@ from modules.color_utils import (
|
|
15 |
detect_color_format,
|
16 |
update_color_opacity
|
17 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def open_image(image_path):
|
20 |
"""
|
@@ -30,8 +42,11 @@ def open_image(image_path):
|
|
30 |
Raises:
|
31 |
Exception: If there is an error opening the image.
|
32 |
"""
|
|
|
|
|
33 |
import requests
|
34 |
try:
|
|
|
35 |
# Strip leading and trailing double quotation marks, if present
|
36 |
image_path = image_path.strip('"')
|
37 |
if image_path.startswith('http'):
|
@@ -369,6 +384,7 @@ def alpha_composite_with_control(base_image, image_with_alpha, alpha_percent=100
|
|
369 |
Returns:
|
370 |
PIL.Image.Image: The resulting image after alpha compositing.
|
371 |
"""
|
|
|
372 |
alpha_multiplier = alpha_percent / 100.0
|
373 |
if isinstance(base_image, str):
|
374 |
base_image = open_image(base_image)
|
@@ -665,6 +681,7 @@ def convert_to_rgba_png(file_path: str) -> tuple[Image, str]:
|
|
665 |
raise UserWarning("No image provided.")
|
666 |
return None, None
|
667 |
try:
|
|
|
668 |
img = open_image(file_path)
|
669 |
print(f"Opened image: {file_path}\n")
|
670 |
# Handle ICO files
|
|
|
6 |
import numpy as np
|
7 |
#from decimal import ROUND_CEILING
|
8 |
from PIL import Image, ImageChops, ImageDraw, ImageEnhance, ImageFilter, ImageDraw, ImageOps, ImageMath
|
9 |
+
from typing import List, Union, is_typeddict
|
10 |
#import numpy as np
|
11 |
#import math
|
12 |
from pathlib import Path
|
|
|
15 |
detect_color_format,
|
16 |
update_color_opacity
|
17 |
)
|
18 |
+
def get_image_from_dict(image_path):
|
19 |
+
if isinstance(image_path, dict) :
|
20 |
+
if 'image' in image_path:
|
21 |
+
image_path = image_path.get('image')
|
22 |
+
elif 'composite' in image_path:
|
23 |
+
image_path = image_path.get('composite')
|
24 |
+
else:
|
25 |
+
print("\n Unknown image dictionary.\n")
|
26 |
+
raise UserWarning("Unknown image dictionary.")
|
27 |
+
return image_path, True
|
28 |
+
else:
|
29 |
+
return image_path, False
|
30 |
|
31 |
def open_image(image_path):
|
32 |
"""
|
|
|
42 |
Raises:
|
43 |
Exception: If there is an error opening the image.
|
44 |
"""
|
45 |
+
if isinstance(image_path, Image.Image):
|
46 |
+
return image_path
|
47 |
import requests
|
48 |
try:
|
49 |
+
image_path, is_dict = get_image_from_dict(image_path)
|
50 |
# Strip leading and trailing double quotation marks, if present
|
51 |
image_path = image_path.strip('"')
|
52 |
if image_path.startswith('http'):
|
|
|
384 |
Returns:
|
385 |
PIL.Image.Image: The resulting image after alpha compositing.
|
386 |
"""
|
387 |
+
image_with_alpha, isdict = get_image_from_dict(image_with_alpha)
|
388 |
alpha_multiplier = alpha_percent / 100.0
|
389 |
if isinstance(base_image, str):
|
390 |
base_image = open_image(base_image)
|
|
|
681 |
raise UserWarning("No image provided.")
|
682 |
return None, None
|
683 |
try:
|
684 |
+
file_path, is_dict = get_image_from_dict(file_path)
|
685 |
img = open_image(file_path)
|
686 |
print(f"Opened image: {file_path}\n")
|
687 |
# Handle ICO files
|