Spaces:
Running
on
Zero
Running
on
Zero
Rearranging UI, working on depth
Browse files- .gitignore +2 -1
- app.py +44 -41
- images/prerendered/alien_world_3.png +2 -2
- utils/constants.py +1 -1
.gitignore
CHANGED
|
@@ -164,4 +164,5 @@ cython_debug/
|
|
| 164 |
/src/__pycache__
|
| 165 |
/utils/__pycache__
|
| 166 |
/__pycache__
|
| 167 |
-
/temp_models
|
|
|
|
|
|
| 164 |
/src/__pycache__
|
| 165 |
/utils/__pycache__
|
| 166 |
/__pycache__
|
| 167 |
+
/temp_models
|
| 168 |
+
/.vscode/settings.json
|
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
# Import constants
|
| 3 |
import numpy as np
|
|
@@ -7,7 +9,7 @@ from typing import Optional, Union, List, Tuple
|
|
| 7 |
from PIL import Image, ImageFilter
|
| 8 |
import cv2
|
| 9 |
import utils.constants as constants
|
| 10 |
-
|
| 11 |
|
| 12 |
from haishoku.haishoku import Haishoku
|
| 13 |
|
|
@@ -15,10 +17,10 @@ from tempfile import NamedTemporaryFile
|
|
| 15 |
import atexit
|
| 16 |
import random
|
| 17 |
#import accelerate
|
| 18 |
-
from transformers import AutoTokenizer, DPTImageProcessor, DPTForDepthEstimation
|
| 19 |
from pathlib import Path
|
| 20 |
import logging
|
| 21 |
-
|
| 22 |
import gc
|
| 23 |
|
| 24 |
IS_SHARED_SPACE = constants.IS_SHARED_SPACE
|
|
@@ -32,7 +34,6 @@ from utils.color_utils import (
|
|
| 32 |
update_color_opacity,
|
| 33 |
)
|
| 34 |
from utils.misc import (get_filename, pause, convert_ratio_to_dimensions) #install_cuda_toolkit,install_torch, _get_output, setup_runtime_env)
|
| 35 |
-
#from utils.depth_estimation import generate_depth_button_click
|
| 36 |
|
| 37 |
from utils.image_utils import (
|
| 38 |
change_color,
|
|
@@ -87,7 +88,8 @@ PIPELINE_CLASSES = {
|
|
| 87 |
"FluxControlPipeline": FluxControlPipeline
|
| 88 |
}
|
| 89 |
|
| 90 |
-
import
|
|
|
|
| 91 |
|
| 92 |
input_image_palette = []
|
| 93 |
current_prerendered_image = gr.State("./images/images/Beeuty-1.png")
|
|
@@ -297,7 +299,7 @@ class Condition(object):
|
|
| 297 |
type_id = torch.ones_like(ids[:, :1]) * self.type_id
|
| 298 |
return tokens, ids, type_id
|
| 299 |
|
| 300 |
-
@spaces.GPU(progress=gr.Progress(track_tqdm=True))
|
| 301 |
def generate_image_lowmem(
|
| 302 |
text,
|
| 303 |
neg_prompt=None,
|
|
@@ -342,7 +344,7 @@ def generate_image_lowmem(
|
|
| 342 |
if pipeline_name == "FluxPipeline":
|
| 343 |
pipe.enable_model_cpu_offload()
|
| 344 |
pipe.vae.enable_slicing()
|
| 345 |
-
pipe.vae.enable_tiling()
|
| 346 |
else:
|
| 347 |
pipe.enable_model_cpu_offload()
|
| 348 |
|
|
@@ -593,10 +595,10 @@ def generate_ai_image_local (
|
|
| 593 |
return tmp.name
|
| 594 |
except Exception as e:
|
| 595 |
print(f"Error generating AI image: {e}")
|
| 596 |
-
gc.collect()
|
| 597 |
return None
|
| 598 |
|
| 599 |
-
|
| 600 |
def generate_input_image_click(map_option, prompt_textbox_value, negative_prompt_textbox_value, model_textbox_value, randomize_seed=True, seed=None, use_conditioned_image=False, strength=0.5, image_format="16:9", scale_factor=(8/3), progress=gr.Progress(track_tqdm=True)):
|
| 601 |
if randomize_seed:
|
| 602 |
seed = random.randint(0, constants.MAX_SEED)
|
|
@@ -651,7 +653,7 @@ def generate_input_image_click(map_option, prompt_textbox_value, negative_prompt
|
|
| 651 |
upscaled_image.save(tmp_upscaled.name, format="PNG")
|
| 652 |
constants.temp_files.append(tmp_upscaled.name)
|
| 653 |
print(f"Upscaled image saved to {tmp_upscaled.name}")
|
| 654 |
-
gc.collect()
|
| 655 |
# Return the path of the upscaled image
|
| 656 |
return tmp_upscaled.name
|
| 657 |
|
|
@@ -689,12 +691,13 @@ def add_border(image, mask_width, mask_height, blank_color):
|
|
| 689 |
|
| 690 |
################################## DEPTH ESTIMATION ##################################
|
| 691 |
|
|
|
|
|
|
|
|
|
|
| 692 |
|
| 693 |
-
|
| 694 |
def estimate_depth(image):
|
| 695 |
-
|
| 696 |
-
image_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
|
| 697 |
-
depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large", ignore_mismatched_sizes=True)
|
| 698 |
|
| 699 |
# Ensure image is in RGB mode
|
| 700 |
if image.mode != "RGB":
|
|
@@ -736,7 +739,7 @@ def estimate_depth(image):
|
|
| 736 |
|
| 737 |
return depth_pil, output
|
| 738 |
|
| 739 |
-
|
| 740 |
def create_3d_model(rgb_image, depth_array, voxel_size_factor=0.01):
|
| 741 |
import open3d as o3d
|
| 742 |
depth_o3d = o3d.geometry.Image(depth_array.astype(np.float32))
|
|
@@ -745,7 +748,7 @@ def create_3d_model(rgb_image, depth_array, voxel_size_factor=0.01):
|
|
| 745 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 746 |
rgb_o3d,
|
| 747 |
depth_o3d,
|
| 748 |
-
convert_rgb_to_intensity=
|
| 749 |
)
|
| 750 |
|
| 751 |
# Create a point cloud from the RGBD image
|
|
@@ -782,6 +785,7 @@ def generate_depth_and_3d(input_image_path, voxel_size_factor):
|
|
| 782 |
model_path = create_3d_model(resized_image, depth_array, voxel_size_factor=voxel_size_factor)
|
| 783 |
return depth_image, model_path
|
| 784 |
|
|
|
|
| 785 |
def generate_depth_button_click(depth_image_source, voxel_size_factor, input_image, output_image, overlay_image, bordered_image_output):
|
| 786 |
if depth_image_source == "Input Image":
|
| 787 |
image_path = input_image
|
|
@@ -798,7 +802,7 @@ def generate_depth_button_click(depth_image_source, voxel_size_factor, input_ima
|
|
| 798 |
def getVersions():
|
| 799 |
return versions_html()
|
| 800 |
|
| 801 |
-
generate_input_image_click.zerogpu = True
|
| 802 |
#generate_depth_button_click.zerogpu = True
|
| 803 |
#def main(debug=False):
|
| 804 |
title = "HexaGrid Creator"
|
|
@@ -1020,17 +1024,16 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty')
|
|
| 1020 |
with gr.Column(scale=2):
|
| 1021 |
with gr.Accordion("Template Image Styles", open = False):
|
| 1022 |
with gr.Row():
|
| 1023 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", minimum=0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
| 1027 |
with gr.Column():
|
|
|
|
| 1028 |
replace_input_image_button = gr.Button(
|
| 1029 |
"Replace Input Image",
|
| 1030 |
elem_id="prerendered_replace_input_image_button",
|
| 1031 |
elem_classes="solid"
|
| 1032 |
-
)
|
| 1033 |
-
with gr.Column():
|
| 1034 |
generate_input_image_from_gallery = gr.Button(
|
| 1035 |
"Generate AI Image from Gallery",
|
| 1036 |
elem_id="generate_input_image_from_gallery",
|
|
@@ -1212,21 +1215,21 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty')
|
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
-
|
| 1216 |
-
logging.basicConfig(
|
| 1217 |
-
|
| 1218 |
-
)
|
| 1219 |
-
logging.info("Environment Variables: %s" % os.environ)
|
| 1220 |
-
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
-
|
| 1224 |
-
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
|
| 1230 |
-
|
| 1231 |
-
hexaGrid.queue(default_concurrency_limit=1,max_size=12,api_open=False)
|
| 1232 |
-
hexaGrid.launch(allowed_paths=["assets","/","./assets","images","./images", "./images/prerendered"], favicon_path="./assets/favicon.ico", max_file_size="10mb")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
import os
|
| 4 |
# Import constants
|
| 5 |
import numpy as np
|
|
|
|
| 9 |
from PIL import Image, ImageFilter
|
| 10 |
import cv2
|
| 11 |
import utils.constants as constants
|
| 12 |
+
|
| 13 |
|
| 14 |
from haishoku.haishoku import Haishoku
|
| 15 |
|
|
|
|
| 17 |
import atexit
|
| 18 |
import random
|
| 19 |
#import accelerate
|
| 20 |
+
from transformers import AutoTokenizer , DPTImageProcessor, DPTForDepthEstimation
|
| 21 |
from pathlib import Path
|
| 22 |
import logging
|
| 23 |
+
logging.getLogger("transformers.modeling_utils").setLevel(logging.ERROR)
|
| 24 |
import gc
|
| 25 |
|
| 26 |
IS_SHARED_SPACE = constants.IS_SHARED_SPACE
|
|
|
|
| 34 |
update_color_opacity,
|
| 35 |
)
|
| 36 |
from utils.misc import (get_filename, pause, convert_ratio_to_dimensions) #install_cuda_toolkit,install_torch, _get_output, setup_runtime_env)
|
|
|
|
| 37 |
|
| 38 |
from utils.image_utils import (
|
| 39 |
change_color,
|
|
|
|
| 88 |
"FluxControlPipeline": FluxControlPipeline
|
| 89 |
}
|
| 90 |
|
| 91 |
+
#from utils.depth_estimation import generate_depth_and_3d
|
| 92 |
+
|
| 93 |
|
| 94 |
input_image_palette = []
|
| 95 |
current_prerendered_image = gr.State("./images/images/Beeuty-1.png")
|
|
|
|
| 299 |
type_id = torch.ones_like(ids[:, :1]) * self.type_id
|
| 300 |
return tokens, ids, type_id
|
| 301 |
|
| 302 |
+
@spaces.GPU(duration=150, progress=gr.Progress(track_tqdm=True))
|
| 303 |
def generate_image_lowmem(
|
| 304 |
text,
|
| 305 |
neg_prompt=None,
|
|
|
|
| 344 |
if pipeline_name == "FluxPipeline":
|
| 345 |
pipe.enable_model_cpu_offload()
|
| 346 |
pipe.vae.enable_slicing()
|
| 347 |
+
#pipe.vae.enable_tiling()
|
| 348 |
else:
|
| 349 |
pipe.enable_model_cpu_offload()
|
| 350 |
|
|
|
|
| 595 |
return tmp.name
|
| 596 |
except Exception as e:
|
| 597 |
print(f"Error generating AI image: {e}")
|
| 598 |
+
#gc.collect()
|
| 599 |
return None
|
| 600 |
|
| 601 |
+
#@spaces.GPU(duration=140)
|
| 602 |
def generate_input_image_click(map_option, prompt_textbox_value, negative_prompt_textbox_value, model_textbox_value, randomize_seed=True, seed=None, use_conditioned_image=False, strength=0.5, image_format="16:9", scale_factor=(8/3), progress=gr.Progress(track_tqdm=True)):
|
| 603 |
if randomize_seed:
|
| 604 |
seed = random.randint(0, constants.MAX_SEED)
|
|
|
|
| 653 |
upscaled_image.save(tmp_upscaled.name, format="PNG")
|
| 654 |
constants.temp_files.append(tmp_upscaled.name)
|
| 655 |
print(f"Upscaled image saved to {tmp_upscaled.name}")
|
| 656 |
+
#gc.collect()
|
| 657 |
# Return the path of the upscaled image
|
| 658 |
return tmp_upscaled.name
|
| 659 |
|
|
|
|
| 691 |
|
| 692 |
################################## DEPTH ESTIMATION ##################################
|
| 693 |
|
| 694 |
+
# Load models once during module import
|
| 695 |
+
image_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large",)
|
| 696 |
+
depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large", ignore_mismatched_sizes=True)
|
| 697 |
|
| 698 |
+
@spaces.GPU()
|
| 699 |
def estimate_depth(image):
|
| 700 |
+
|
|
|
|
|
|
|
| 701 |
|
| 702 |
# Ensure image is in RGB mode
|
| 703 |
if image.mode != "RGB":
|
|
|
|
| 739 |
|
| 740 |
return depth_pil, output
|
| 741 |
|
| 742 |
+
@spaces.GPU()
|
| 743 |
def create_3d_model(rgb_image, depth_array, voxel_size_factor=0.01):
|
| 744 |
import open3d as o3d
|
| 745 |
depth_o3d = o3d.geometry.Image(depth_array.astype(np.float32))
|
|
|
|
| 748 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 749 |
rgb_o3d,
|
| 750 |
depth_o3d,
|
| 751 |
+
convert_rgb_to_intensity=True
|
| 752 |
)
|
| 753 |
|
| 754 |
# Create a point cloud from the RGBD image
|
|
|
|
| 785 |
model_path = create_3d_model(resized_image, depth_array, voxel_size_factor=voxel_size_factor)
|
| 786 |
return depth_image, model_path
|
| 787 |
|
| 788 |
+
|
| 789 |
def generate_depth_button_click(depth_image_source, voxel_size_factor, input_image, output_image, overlay_image, bordered_image_output):
|
| 790 |
if depth_image_source == "Input Image":
|
| 791 |
image_path = input_image
|
|
|
|
| 802 |
def getVersions():
|
| 803 |
return versions_html()
|
| 804 |
|
| 805 |
+
#generate_input_image_click.zerogpu = True
|
| 806 |
#generate_depth_button_click.zerogpu = True
|
| 807 |
#def main(debug=False):
|
| 808 |
title = "HexaGrid Creator"
|
|
|
|
| 1024 |
with gr.Column(scale=2):
|
| 1025 |
with gr.Accordion("Template Image Styles", open = False):
|
| 1026 |
with gr.Row():
|
| 1027 |
+
with gr.Column(scale=2):
|
| 1028 |
+
# Gallery from PRE_RENDERED_IMAGES GOES HERE
|
| 1029 |
+
prerendered_image_gallery = gr.Gallery(label="Image Gallery", show_label=True, value=build_prerendered_images(constants.pre_rendered_maps_paths), elem_id="gallery", elem_classes="solid", type="filepath", columns=[3], rows=[3], preview=False ,object_fit="contain", height="auto", format="png",allow_preview=False)
|
|
|
|
| 1030 |
with gr.Column():
|
| 1031 |
+
image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", minimum=0, maximum=1.0, value=0.8, step=0.01, interactive=True)
|
| 1032 |
replace_input_image_button = gr.Button(
|
| 1033 |
"Replace Input Image",
|
| 1034 |
elem_id="prerendered_replace_input_image_button",
|
| 1035 |
elem_classes="solid"
|
| 1036 |
+
)
|
|
|
|
| 1037 |
generate_input_image_from_gallery = gr.Button(
|
| 1038 |
"Generate AI Image from Gallery",
|
| 1039 |
elem_id="generate_input_image_from_gallery",
|
|
|
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
+
if __name__ == "__main__":
|
| 1219 |
+
logging.basicConfig(
|
| 1220 |
+
format="[%(levelname)s] %(asctime)s %(message)s", level=logging.INFO
|
| 1221 |
+
)
|
| 1222 |
+
logging.info("Environment Variables: %s" % os.environ)
|
| 1223 |
+
# if _get_output(["nvcc", "--version"]) is None:
|
| 1224 |
+
# logging.info("Installing CUDA toolkit...")
|
| 1225 |
+
# install_cuda_toolkit()
|
| 1226 |
+
# else:
|
| 1227 |
+
# logging.info("Detected CUDA: %s" % _get_output(["nvcc", "--version"]))
|
| 1228 |
+
|
| 1229 |
+
# logging.info("Installing CUDA extensions...")
|
| 1230 |
+
# setup_runtime_env()
|
| 1231 |
+
#main(os.getenv("DEBUG") == "1")
|
| 1232 |
+
#main()
|
| 1233 |
+
|
| 1234 |
+
hexaGrid.queue(default_concurrency_limit=1,max_size=12,api_open=False)
|
| 1235 |
+
hexaGrid.launch(allowed_paths=["assets","/","./assets","images","./images", "./images/prerendered"], favicon_path="./assets/favicon.ico", max_file_size="10mb")
|
images/prerendered/alien_world_3.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
utils/constants.py
CHANGED
|
@@ -46,7 +46,7 @@ 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. Overhead view.",
|
| 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 |
-
"
|
| 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.",
|
|
|
|
| 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. Overhead view.",
|
| 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 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.",
|