import os #Set the environment variables os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:256,expandable_segments:True" IS_SHARED_SPACE = "Surn/HexaGrid" in os.environ.get('SPACE_ID', '') # 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' os.environ['USE_FLASH_ATTENTION'] = '1' os.environ['XFORMERS_FORCE_DISABLE_TRITON']= '1' # constants.py contains all the constants used in the project os.environ["HF_TOKEN"] = "" HF_API_TOKEN = os.getenv("HF_TOKEN") default_lut_example_img = "./LUT/daisy.jpg" PROMPTS = { "BorderBlack": "eight_color (tabletop_map built from small hexagon pieces) as ((empty black on all sides), barren alien_world_map), with light_blue_is_rivers and brown_is_mountains and red_is_volcano and [white_is_snow at the top and bottom of map] as (four_color background: light_blue, green, tan, brown), horizontal_gradient is (brown to tan to green to light_blue to blue) and vertical_gradient is (white to blue to (green, tan and red) to blue to white), (middle is dark, no_reflections, no_shadows), ((partial hexes on edges and sides are black))", "Earth": "eight_color (tabletop_map built from small hexagon pieces) as world_map, with light_blue_is_rivers and brown_is_mountains and red_is_volcano and [white_is_snow at the top and bottom of map] as (four_color background: light_blue, green, tan, brown), horizontal_gradient is (brown to tan to green to light_blue to blue) and vertical_gradient is (white to blue to (green, tan and red) to blue to white), (middle is dark, no_reflections, no_shadows), ((partial hexes on edges and sides are black)), overhead_view, from_above", "Map3": "top-down, bird's-eye view of A mystic forest-themed map viewed from directly above, showcasing detailed terrain features such as lakes, dense forests, magical flora, and hexagonal grids. The map is designed for tabletop gaming, emphasizing clarity and strategic elements, eight_color (tabletop_map built from small hexagon pieces) as alien_forest_world_map, with light_blue_is_lakes and green_is_forests and purple_is_alien_flora and [white_is_snow at the top and bottom of map] as (four_color background: light_blue, green, purple, brown), horizontal_gradient is (green to purple to light_blue to blue) and vertical_gradient is (white to blue to (green, purple and brown) to blue to white), (middle is dark, no_reflections, no_shadows), ((partial hexes on edges and sides are black))", "Map4": "A top-down, bird's-eye view of a medieval battlefield map for tabletop games, eight_color (tabletop_map built from small hexagon pieces) as mystic_forest_world_map, with teal_is_lakes and dark_green_is_forest and violet_is_magic_fauna and [white_is_snow at the top and bottom of map] as (four_color background: teal, dark_green, violet, brown), horizontal_gradient is (brown to violet to teal to blue) and vertical_gradient is (white to blue to (dark_green, violet and brown) to blue to white), (middle is enchanted, no_reflections, no_shadows), ((partial hexes on edges and sides are black)), viewed from above, flat and illustrative, not a map of the Earth", "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 the top and bottom. Background 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. Uses a four-color background: 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 hexagonal grids. Designed for clarity in tabletop gaming. Background 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. Background 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, missing realistic map of the Earth, 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" ] # 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" } # 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" } } ], "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 ]