Spaces:
Running
on
Zero
Running
on
Zero
| # utils/constants.py | |
| # constants.py contains all the constants used in the project such as the default LUT example image, prompts, negative prompts, pre-rendered maps, models, LoRA weights, and more. | |
| # execptions made for some environmental variables | |
| import os | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| import numpy as np | |
| #Set the environment variables | |
| os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:256,expandable_segments:True" | |
| os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' | |
| #os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2' | |
| os.environ['CUDA_MODULE_LOADING']='LAZY' | |
| os.environ['USE_FLASH_ATTENTION'] = '1' | |
| os.environ['XFORMERS_FORCE_DISABLE_TRITON']= '1' | |
| #os.environ['XFORMERS_FORCE_DISABLE_TORCHSCRIPT']= '1' | |
| #os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" | |
| os.environ["PYTORCH_NVML_BASED_CUDA_CHECK"] = "1" | |
| os.environ["CUDA_VISIBLE_DEVICES"] = "0" | |
| os.environ["NVIDIA_VISIBLE_DEVICES"] = "0" | |
| os.environ["ZEROGPU_VERSION"] = "2" | |
| os.environ["ZEROGPU_V2"] = "true" | |
| os.environ["ZERO_GPU_V2"] = "true" | |
| os.environ["ZERO_GPU_PATCH_TORCH_DEVICE"]='1' | |
| IS_SHARED_SPACE = "Surn/HexaGrid" in os.environ.get('SPACE_ID', '') | |
| # Load environment variables from .env file | |
| dotenv_path = Path(__file__).parent.parent / '.env' | |
| load_dotenv(dotenv_path) | |
| # Set the temporary folder location | |
| #os.environ['TEMP'] = r'e:\\TMP' | |
| #os.environ['TMPDIR'] = r'e:\\TMP' | |
| #os.environ['XDG_CACHE_HOME'] = r'E:\\cache' | |
| HF_API_TOKEN = os.getenv("HF_TOKEN") | |
| if not HF_API_TOKEN: | |
| raise ValueError("HF_TOKEN is not set. Please check your .env file.") | |
| default_lut_example_img = "./LUT/daisy.jpg" | |
| MAX_SEED = np.iinfo(np.int32).max | |
| TARGET_SIZE = (2688,1536) | |
| PROMPTS = { | |
| "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.", | |
| "Medieval Battlefield": "Top-down view of a medieval battlefield map featuring lakes, forests, and magic fauna. Emphasizes clarity and strategy for tabletop games. Colors: teal, dark green, violet, brown. Partial edge hexes are black. Viewed from above.", | |
| "Prompt": None # Indicates that the prompt should be taken from prompt_textbox | |
| } | |
| NEGATIVE_PROMPTS = { | |
| "BorderBlack": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Earth": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, isometric", | |
| "Map3": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Map4": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Alien Landscape": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Alien World": "Earth, humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Mystic Forest": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Medieval Battlefield": "humans, modern_buildings, vehicles, text, logos, reflections, shadows, realistic map of the Earth, isometric", | |
| "Prompt": None # Indicates that the negative prompt should be taken from negative_prompt_textbox | |
| } | |
| # Directory containing the pre-rendered hexagon maps | |
| ASSETS_DIR = "images/prerendered" | |
| # List of pre-rendered hexagon map files | |
| PRE_RENDERED_MAPS = [ | |
| "alien_orb_land_1.png", | |
| "alien_prarie_1.png", | |
| "alien_world_1.png", | |
| "alien_world_2.png", | |
| "alien_world_3.png", | |
| "alien_world_4.png", | |
| "alien_world_5.png", | |
| "canyon_water_1.png", | |
| "CONQ_Caustic_Valley.png", | |
| "CONQ_Frozen_City.png", | |
| "CONQ_Hellebore_Springs.png", | |
| "CONQ_Terra_Therma.png", | |
| "CONQ_Viridian_Bog.png", | |
| "dark_dirt_elevations_1.png", | |
| "elevated_peninsula_1.png", | |
| "Firefly_alien_canyons_1.png", | |
| "Firefly_alien_canyons_2.png", | |
| "Firefly_alien_canyons_2.png", | |
| "Firefly_alien_dry_canyons_1.png", | |
| "Firefly_alien_dry_canyons_2.png", | |
| "Firefly_alien_map_1.png", | |
| "Firefly_hpg_terrain_1.png", | |
| "Firefly_hpg_terrain_2.png", | |
| "Firefly_river_dry_1.png", | |
| "Firefly_river_running_1.png", | |
| "Firefly_topographical_alien_desert_1.png", | |
| "Firefly_topographical_canyon_1.png", | |
| "Firefly_topographical_height_map_1.png", | |
| "Firefly_topographical_height_map_2.png", | |
| "Firefly_topographical_height_map_3.png", | |
| "Firefly_topographical_height_map_5.png", | |
| "Firefly_topographical_height_map_6.png", | |
| "Firefly_topographical_marble_1.png", | |
| "Firefly_topographical_moon_1.png", | |
| "green_farming alien_world_1.png", | |
| "green_farming alien_world_2.png", | |
| "grey_barren_alien_world_1.png", | |
| "grey_barren_alien_world_2.png", | |
| "grey_barren_alien_world_3.png", | |
| "grey_barren_alien_world_4.png", | |
| "grey_barren_alien_world_5.png", | |
| "grey_barren_alien_world_6.png", | |
| "grey_barren_alien_world_7.png", | |
| "grey_waterless_alien_world_map.png", | |
| "grid_1.png", | |
| "Hex_gen_map.PNG", | |
| "hex_grass_dirty.png", | |
| "hex_military_industrial alien_world_map.png", | |
| "hex_mixed_elevations_battlefield_1.png", | |
| "hex_mixed_elevations_battlefield_2.png", | |
| "mixed_elevations_battlefield_3.png", | |
| "n6W9Hc.png", | |
| "oasis_mixed_elevations_1.png", | |
| "pic526383.png", | |
| "red_volcanic_alien_1.png", | |
| "red_volcanic_alien_2.png", | |
| "red_volcanic_alien_3.png", | |
| "red_volcanic_alien_4.png", | |
| "roadway_1.png", | |
| "snowy_rolling_hills_1.png", | |
| "volcanic alien_world_map.png", | |
| "war-torn_post-apocalyptic_alien_world_map.png" | |
| ] | |
| # Create full paths for pre-rendered maps | |
| pre_rendered_maps_paths = [os.path.join(ASSETS_DIR, map_file).replace("\\", "/") for map_file in PRE_RENDERED_MAPS] | |
| pre_rendered_maps_paths_api_file = [f"./gradio_api/file={map_path}" for map_path in pre_rendered_maps_paths] | |
| # Generate a dictionary with cleaned-up names as keys and file paths as values | |
| PRE_RENDERED_MAPS_JSON = { | |
| os.path.splitext(file.replace("_", " ").replace("-", " ").replace(" ", " ").strip())[0]: os.path.join(ASSETS_DIR, file) | |
| for file in PRE_RENDERED_MAPS | |
| } | |
| PRE_RENDERED_MAPS_JSON = "{'alien world 1': 'images/prerendered/alien_world_1.jpg', 'alien world 2': 'images/prerendered/alien_world_2.jpg', 'alien world 3': 'images/prerendered/alien_world_3.jpg', 'alien world 4': 'images/prerendered/alien_world_4.jpg', 'alien world 5': 'images/prerendered/alien_world_5.jpg', 'green farming alien world 1': 'images/prerendered/green_farming alien_world_1.jpg', 'green farming alien world 2': 'images/prerendered/green_farming alien_world_2.jpg', 'grey barren alien world 1': 'images/prerendered/grey_barren_alien_world_1.jpg', 'grey barren alien world 2': 'images/prerendered/grey_barren_alien_world_2.jpg', 'grey barren alien world 3': 'images/prerendered/grey_barren_alien_world_3.jpg', 'grey barren alien world 4': 'images/prerendered/grey_barren_alien_world_4.jpg', 'grey barren alien world 5': 'images/prerendered/grey_barren_alien_world_5.jpg', 'grey barren alien world 6': 'images/prerendered/grey_barren_alien_world_6.jpg', 'grey barren alien world 7': 'images/prerendered/grey_barren_alien_world_7.jpg', 'grey waterless alien world map': 'images/prerendered/grey_waterless_alien_world_map.jpg', 'Hex gen map': 'images/prerendered/Hex_gen_map.PNG', 'military industrial alien world map': 'images/prerendered/military_industrial alien_world_map.jpg', 'red volcanic alien 1': 'images/prerendered/red_volcanic_alien_1.jpg', 'red volcanic alien 2': 'images/prerendered/red_volcanic_alien_2.jpg', 'red volcanic alien 3': 'images/prerendered/red_volcanic_alien_3.jpg', 'red volcanic alien 4': 'images/prerendered/red_volcanic_alien_4.jpg', 'volcanic alien world map': 'images/prerendered/volcanic alien_world_map.jpg', 'war torn post apocalyptic alien world map': 'images/prerendered/war-torn_post-apocalyptic_alien_world_map.jpg'}" | |
| # Available FLUX model names | |
| MODELS = [ | |
| "black-forest-labs/FLUX.1-schnell", | |
| "black-forest-labs/FLUX.1-dev", | |
| "ostris/Flex.1-alpha" | |
| ] | |
| # Available LoRA weights | |
| LORA_WEIGHTS = [ | |
| "Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design", | |
| "Borcherding/FLUX.1-dev-LoRA-FractalLand-v0.1", | |
| "Cossale/Frames2-Flex.1", | |
| "XLabs-AI/flux-lora-collection/anime_lora.safetensors", | |
| "XLabs-AI/flux-lora-collection/scenery_lora.safetensors", | |
| "XLabs-AI/flux-lora-collection/disney_lora.safetensors", | |
| "XLabs-AI/flux-RealismLora" | |
| ] | |
| # Map each LoRA weight to its corresponding model | |
| LORA_TO_MODEL = { | |
| "Yuanshi/OminiControl": "black-forest-labs/FLUX.1-schnell", | |
| "Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design": "black-forest-labs/FLUX.1-dev", | |
| "Borcherding/FLUX.1-dev-LoRA-FractalLand-v0.1": "black-forest-labs/FLUX.1-dev", | |
| "Cossale/Frames2-Flex.1": "ostris/Flex.1-alpha", | |
| "AlekseyCalvin/HSTcolorFlexAlpha": "ostris/Flex.1-alpha", | |
| "XLabs-AI/flux-lora-collection/anime_lora.safetensors":"black-forest-labs/FLUX.1-dev", | |
| "XLabs-AI/flux-lora-collection/scenery_lora.safetensors":"black-forest-labs/FLUX.1-dev", | |
| "XLabs-AI/flux-lora-collection/disney_lora.safetensors":"black-forest-labs/FLUX.1-dev", | |
| "XLabs-AI/flux-RealismLora":"black-forest-labs/FLUX.1-dev" | |
| } | |
| condition_type = ["depth", "canny", "subject", "coloring", "deblurring", "fill", "redux"] | |
| # Detailed LoRA weight configurations | |
| LORA_DETAILS = { | |
| "AlekseyCalvin/HSTcolorFlexAlpha" : [ | |
| { | |
| "trigger_words": "(6kStepsCkpt) HST style autochrome photograph", | |
| }, | |
| { | |
| "weight_name": "HSToricColorFlex_6000steps_LoRAforFluxOrFlex_32dim64alpha.safetensors", | |
| }, | |
| { | |
| "notes": "You should use (6kStepsCkpt) HST style autochrome photograph as trigger words." | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "30" | |
| } | |
| } | |
| ], | |
| "XLabs-AI/flux-lora-collection/anime_lora.safetensors":[ | |
| { | |
| "lora_collection": "XLabs-AI/flux-lora-collection", | |
| "weight_name": "anime_lora.safetensors" | |
| }, | |
| { | |
| "trigger_words": "anime,", | |
| }, | |
| { | |
| "notes": "You should use ',anime' as trigger words at the end. @6min" | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "30" | |
| } | |
| } | |
| ], | |
| "XLabs-AI/flux-lora-collection/scenery_lora.safetensors":[ | |
| { | |
| "lora_collection": "XLabs-AI/flux-lora-collection", | |
| "weight_name": "scenery_lora.safetensors" | |
| }, | |
| { | |
| "trigger_words": "scenery style,", | |
| }, | |
| { | |
| "notes": "You should use ',scenery style' as trigger words at the end. @6min" | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "30" | |
| } | |
| } | |
| ], | |
| "XLabs-AI/flux-lora-collection/disney_lora.safetensors":[ | |
| { | |
| "lora_collection": "XLabs-AI/flux-lora-collection", | |
| "weight_name": "disney_lora.safetensors" | |
| }, | |
| { | |
| "trigger_words": "disney style,", | |
| }, | |
| { | |
| "notes": "You should use ',disney style' as trigger words at the end. @12min " | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "30" | |
| } | |
| } | |
| ], | |
| "XLabs-AI/flux-RealismLora":[ | |
| { | |
| "notes": "No trigger words but 8k, Animatrix illustration style, fantasy style, natural photo cinematic should all work @6min" | |
| }, | |
| { | |
| "parameters" :{ | |
| "guidance_scale": "3.2", | |
| "num_inference_steps": "34", | |
| "scale": "0.85" | |
| } | |
| } | |
| ], | |
| "Cossale/Frames2-Flex.1": [ | |
| { | |
| "weight_name": "backdrops_v2.safetensors", | |
| "adapter_name": "backdrops_v2" | |
| }, | |
| { | |
| "trigger_words": "FRM$", | |
| }, | |
| { | |
| "notes": "You should use FRM$ as trigger words. @1.5 minutes" | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "50" | |
| } | |
| } | |
| ], | |
| "Yuanshi/OminiControl": [ | |
| { | |
| "weight_name": "omini/subject_512.safetensors", | |
| "adapter_name": "subject_512" | |
| }, | |
| { | |
| "weight_name": "omini/subject_1024_beta.safetensors", | |
| "adapter_name": "subject_1024" | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "8", | |
| "guidance_scale": "0" | |
| } | |
| }, | |
| { | |
| "notes": "Select an Image as a guide." | |
| } | |
| ], | |
| "Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design": [ | |
| { | |
| "notes": "You should use wablogo, logo, Minimalist as trigger words.. @4.8min" | |
| }, | |
| { | |
| "trigger_words": "wablogo, logo, Minimalist ", | |
| }, | |
| { | |
| "pipe" :{ | |
| "fuse_lora": {"lora_scale":0.8} | |
| } | |
| }, | |
| { | |
| "parameters" :{ | |
| "num_inference_steps": "38" | |
| } | |
| } | |
| ], | |
| "Borcherding/FLUX.1-dev-LoRA-FractalLand-v0.1": [ | |
| { | |
| "notes": "Use fractalLand at the start of the prompts to activate the fractal elements. . @4.8min" | |
| }, | |
| { | |
| "trigger_words": "fractalLand ", | |
| }, | |
| { | |
| "parameters" :{ | |
| "max_sequence_length": "512", | |
| "guidance_scale": "3.5", | |
| "num_inference_steps": "38" | |
| } | |
| } | |
| ] | |
| } | |
| # Read the contents of the LUT folder, output to a list | |
| lut_folder = "./LUT" | |
| lut_files = [os.path.join(lut_folder, f).replace("\\", "/") for f in os.listdir(lut_folder) if f.endswith(".cube")] | |
| temp_files = [] | |
| cards = [ | |
| "2♥️", "3♥️", "4♥️", "5♥️", "6♥️", "7♥️", "8♥️", "9♥️", "10♥️", "J♥️", "Q♥️", "K♥️", "A♥️", | |
| "2♦️", "3♦️", "4♦️", "5♦️", "6♦️", "7♦️", "8♦️", "9♦️", "10♦️", "J♦️", "Q♦️", "K♦️", "A♦️", | |
| "2♣️", "3♣️", "4♣️", "5♣️", "6♣️", "7♣️", "8♣️", "9♣️", "10♣️", "J♣️", "Q♣️", "K♣️", "A♣️", | |
| "2♠️", "3♠️", "4♠️", "5♠️", "6♠️", "7♠️", "8♠️", "9♠️", "10♠️", "J♠️", "Q♠️", "K♠️", "A♠️" | |
| ] | |
| cards_alternating = [ | |
| "2♥️", "3♥️", "4♥️", "5♥️", "6♥️", "7♥️", "8♥️", "9♥️", "10♥️", "J♥️", "Q♥️", "K♥️", "A♥️", | |
| "2♣️", "3♣️", "4♣️", "5♣️", "6♣️", "7♣️", "8♣️", "9♣️", "10♣️", "J♣️", "Q♣️", "K♣️", "A♣️", | |
| "2♦️", "3♦️", "4♦️", "5♦️", "6♦️", "7♦️", "8♦️", "9♦️", "10♦️", "J♦️", "Q♦️", "K♦️", "A♦️", | |
| "2♠️", "3♠️", "4♠️", "5♠️", "6♠️", "7♠️", "8♠️", "9♠️", "10♠️", "J♠️", "Q♠️", "K♠️", "A♠️" | |
| ] | |
| card_colors = [ | |
| "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", # Hearts | |
| "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", # Diamonds | |
| "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", # Clubs | |
| "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000" # Spades | |
| ] | |
| card_colors_alternating = [ | |
| "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", # Hearts | |
| "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", # Clubs | |
| "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", "#FF0000", # Diamonds | |
| "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000" # Spades | |
| ] |