Spaces:
Running on Zero
Running on Zero
Rearranging UI, working on depth
Browse filesFiles changed (4)
163 unmodified lines164165166167163 unmodified lines/src/__pycache__/utils/__pycache__/__pycache__/temp_models163 unmodified lines164165166167168163 unmodified lines/src/__pycache__/utils/__pycache__/__pycache__/temp_models/.vscode/settings.json
1233 unmodified lines789101112131 unmodified line151617181920212223247 unmodified lines3233343536373848 unmodified lines87888990919293203 unmodified lines29729829930030130230338 unmodified lines342343344345346347348244 unmodified lines59359459559659759859960060160248 unmodified lines65165265365465565665731 unmodified lines68969069169269369469569669769869970035 unmodified lines7367377387397407417422 unmodified lines74574674774874975075130 unmodified lines78278378478578678710 unmodified lines798799800801802803804215 unmodified lines10201021102210231024102510261027102810291030103110321033103410351036175 unmodified lines121212131214121512161217121812191220122112221223122412251226122712281229123012311232import os# Import constantsimport numpy as np3 unmodified linesfrom PIL import Image, ImageFilterimport cv2import utils.constants as constantsimport gradio as grfrom haishoku.haishoku import Haishoku1 unmodified lineimport atexitimport random#import acceleratefrom transformers import AutoTokenizer, DPTImageProcessor, DPTForDepthEstimationfrom pathlib import Pathimport logging#logging.getLogger("transformers.modeling_utils").setLevel(logging.ERROR)import gcIS_SHARED_SPACE = constants.IS_SHARED_SPACE7 unmodified linesupdate_color_opacity,)from utils.misc import (get_filename, pause, convert_ratio_to_dimensions) #install_cuda_toolkit,install_torch, _get_output, setup_runtime_env)#from utils.depth_estimation import generate_depth_button_clickfrom utils.image_utils import (change_color,48 unmodified lines"FluxControlPipeline": FluxControlPipeline}import spacesinput_image_palette = []current_prerendered_image = gr.State("./images/images/Beeuty-1.png")203 unmodified linestype_id = torch.ones_like(ids[:, :1]) * self.type_idreturn tokens, ids, type_id@spaces.GPU(progress=gr.Progress(track_tqdm=True))def generate_image_lowmem(text,neg_prompt=None,38 unmodified linesif pipeline_name == "FluxPipeline":pipe.enable_model_cpu_offload()pipe.vae.enable_slicing()pipe.vae.enable_tiling()else:pipe.enable_model_cpu_offload()244 unmodified linesreturn tmp.nameexcept Exception as e:print(f"Error generating AI image: {e}")gc.collect()return None@spaces.GPU(duration=140)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)):if randomize_seed:seed = random.randint(0, constants.MAX_SEED)48 unmodified linesupscaled_image.save(tmp_upscaled.name, format="PNG")constants.temp_files.append(tmp_upscaled.name)print(f"Upscaled image saved to {tmp_upscaled.name}")gc.collect()# Return the path of the upscaled imagereturn tmp_upscaled.name31 unmodified lines################################## DEPTH ESTIMATION ###################################@spaces.GPU()def estimate_depth(image):# Load models once during module importimage_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large", ignore_mismatched_sizes=True)# Ensure image is in RGB modeif image.mode != "RGB":35 unmodified linesreturn depth_pil, output#@spaces.GPU()def create_3d_model(rgb_image, depth_array, voxel_size_factor=0.01):import open3d as o3ddepth_o3d = o3d.geometry.Image(depth_array.astype(np.float32))2 unmodified linesrgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(rgb_o3d,depth_o3d,convert_rgb_to_intensity=False)# Create a point cloud from the RGBD image30 unmodified linesmodel_path = create_3d_model(resized_image, depth_array, voxel_size_factor=voxel_size_factor)return depth_image, model_pathdef generate_depth_button_click(depth_image_source, voxel_size_factor, input_image, output_image, overlay_image, bordered_image_output):if depth_image_source == "Input Image":image_path = input_image10 unmodified linesdef getVersions():return versions_html()generate_input_image_click.zerogpu = True#generate_depth_button_click.zerogpu = True#def main(debug=False):title = "HexaGrid Creator"215 unmodified lineswith gr.Column(scale=2):with gr.Accordion("Template Image Styles", open = False):with gr.Row():# Gallery from PRE_RENDERED_IMAGES GOES HEREprerendered_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)with gr.Row():image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", minimum=0, maximum=1.0, value=0.8, step=0.01, interactive=True)with gr.Column():replace_input_image_button = gr.Button("Replace Input Image",elem_id="prerendered_replace_input_image_button",elem_classes="solid")with gr.Column():generate_input_image_from_gallery = gr.Button("Generate AI Image from Gallery",elem_id="generate_input_image_from_gallery",175 unmodified lines#if __name__ == "__main__":logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.INFO)logging.info("Environment Variables: %s" % os.environ)# if _get_output(["nvcc", "--version"]) is None:# logging.info("Installing CUDA toolkit...")# install_cuda_toolkit()# else:# logging.info("Detected CUDA: %s" % _get_output(["nvcc", "--version"]))# logging.info("Installing CUDA extensions...")# setup_runtime_env()#main(os.getenv("DEBUG") == "1")#main()hexaGrid.queue(default_concurrency_limit=1,max_size=12,api_open=False)hexaGrid.launch(allowed_paths=["assets","/","./assets","images","./images", "./images/prerendered"], favicon_path="./assets/favicon.ico", max_file_size="10mb")123453 unmodified lines91011121314151 unmodified line171819202122232425267 unmodified lines34353637383948 unmodified lines8889909192939495203 unmodified lines29930030130230330430538 unmodified lines344345346347348349350244 unmodified lines59559659759859960060160260360448 unmodified lines65365465565665765865931 unmodified lines69169269369469569669769869970070170270335 unmodified lines7397407417427437447452 unmodified lines74874975075175275375430 unmodified lines78578678778878979079110 unmodified lines802803804805806807808215 unmodified lines1024102510261027102810291030103110321033103410351036103710381039175 unmodified lines121512161217121812191220122112221223122412251226122712281229123012311232123312341235import gradio as grimport spacesimport os# Import constantsimport numpy as np3 unmodified linesfrom PIL import Image, ImageFilterimport cv2import utils.constants as constantsfrom haishoku.haishoku import Haishoku1 unmodified lineimport atexitimport random#import acceleratefrom transformers import AutoTokenizer , DPTImageProcessor, DPTForDepthEstimationfrom pathlib import Pathimport logginglogging.getLogger("transformers.modeling_utils").setLevel(logging.ERROR)import gcIS_SHARED_SPACE = constants.IS_SHARED_SPACE7 unmodified linesupdate_color_opacity,)from utils.misc import (get_filename, pause, convert_ratio_to_dimensions) #install_cuda_toolkit,install_torch, _get_output, setup_runtime_env)from utils.image_utils import (change_color,48 unmodified lines"FluxControlPipeline": FluxControlPipeline}#from utils.depth_estimation import generate_depth_and_3dinput_image_palette = []current_prerendered_image = gr.State("./images/images/Beeuty-1.png")203 unmodified linestype_id = torch.ones_like(ids[:, :1]) * self.type_idreturn tokens, ids, type_id@spaces.GPU(duration=150, progress=gr.Progress(track_tqdm=True))def generate_image_lowmem(text,neg_prompt=None,38 unmodified linesif pipeline_name == "FluxPipeline":pipe.enable_model_cpu_offload()pipe.vae.enable_slicing()#pipe.vae.enable_tiling()else:pipe.enable_model_cpu_offload()244 unmodified linesreturn tmp.nameexcept Exception as e:print(f"Error generating AI image: {e}")#gc.collect()return None#@spaces.GPU(duration=140)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)):if randomize_seed:seed = random.randint(0, constants.MAX_SEED)48 unmodified linesupscaled_image.save(tmp_upscaled.name, format="PNG")constants.temp_files.append(tmp_upscaled.name)print(f"Upscaled image saved to {tmp_upscaled.name}")#gc.collect()# Return the path of the upscaled imagereturn tmp_upscaled.name31 unmodified lines################################## DEPTH ESTIMATION ################################### Load models once during module importimage_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large",)depth_model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large", ignore_mismatched_sizes=True)@spaces.GPU()def estimate_depth(image):# Ensure image is in RGB modeif image.mode != "RGB":35 unmodified linesreturn depth_pil, output@spaces.GPU()def create_3d_model(rgb_image, depth_array, voxel_size_factor=0.01):import open3d as o3ddepth_o3d = o3d.geometry.Image(depth_array.astype(np.float32))2 unmodified linesrgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(rgb_o3d,depth_o3d,convert_rgb_to_intensity=True)# Create a point cloud from the RGBD image30 unmodified linesmodel_path = create_3d_model(resized_image, depth_array, voxel_size_factor=voxel_size_factor)return depth_image, model_pathdef generate_depth_button_click(depth_image_source, voxel_size_factor, input_image, output_image, overlay_image, bordered_image_output):if depth_image_source == "Input Image":image_path = input_image10 unmodified linesdef getVersions():return versions_html()#generate_input_image_click.zerogpu = True#generate_depth_button_click.zerogpu = True#def main(debug=False):title = "HexaGrid Creator"215 unmodified lineswith gr.Column(scale=2):with gr.Accordion("Template Image Styles", open = False):with gr.Row():with gr.Column(scale=2):# Gallery from PRE_RENDERED_IMAGES GOES HEREprerendered_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)with gr.Column():image_guidance_stength = gr.Slider(label="Image Guidance Strength (prompt percentage)", minimum=0, maximum=1.0, value=0.8, step=0.01, interactive=True)replace_input_image_button = gr.Button("Replace Input Image",elem_id="prerendered_replace_input_image_button",elem_classes="solid")generate_input_image_from_gallery = gr.Button("Generate AI Image from Gallery",elem_id="generate_input_image_from_gallery",175 unmodified linesif __name__ == "__main__":logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.INFO)logging.info("Environment Variables: %s" % os.environ)# if _get_output(["nvcc", "--version"]) is None:# logging.info("Installing CUDA toolkit...")# install_cuda_toolkit()# else:# logging.info("Detected CUDA: %s" % _get_output(["nvcc", "--version"]))# logging.info("Installing CUDA extensions...")# setup_runtime_env()#main(os.getenv("DEBUG") == "1")#main()hexaGrid.queue(default_concurrency_limit=1,max_size=12,api_open=False)hexaGrid.launch(allowed_paths=["assets","/","./assets","images","./images", "./images/prerendered"], favicon_path="./assets/favicon.ico", max_file_size="10mb")
45 unmodified lines4647484950515245 unmodified lines"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.","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.","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.","Scyfi 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.","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.","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.","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.",45 unmodified lines4647484950515245 unmodified lines"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.","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.","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.","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.","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.","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.","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.",
.gitignore+2-1
app.py+44-41
images/prerendered/alien_world_3.png

Large File Pointer Details
- SHA256: 3c4d755120cf953d3925c8423c5e6c8c46dc9a92bb54be9865fb77ae63b8a9a6
- Pointer size: 132 Bytes
- Size of remote file: 6.54 MB

Large File Pointer Details
- SHA256: b7a5deae9ff78aabea23b197982572b13036fc9c59a51789c6c6def93c59cc5f
- Pointer size: 132 Bytes
- Size of remote file: 6.17 MB
utils/constants.py+1-1