File size: 17,859 Bytes
527fcc4
 
 
 
 
 
7a9500a
527fcc4
061d802
492a331
527fcc4
 
ab4cf94
527fcc4
ab4cf94
527fcc4
ab4cf94
527fcc4
8534154
ab4cf94
 
 
 
 
527fcc4
6ef117e
061d802
527fcc4
 
 
 
061d802
3d65503
 
 
061d802
 
527fcc4
 
 
061d802
7a9500a
6dd859c
061d802
 
ab4cf94
 
 
 
 
 
 
 
061d802
 
 
 
492a331
 
061d802
 
 
492a331
061d802
 
 
 
 
 
 
 
 
 
 
 
492a331
 
 
 
 
061d802
492a331
 
 
 
 
061d802
 
 
 
492a331
 
 
 
061d802
 
492a331
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
061d802
 
492a331
061d802
 
 
 
 
 
492a331
 
 
 
061d802
 
492a331
 
061d802
 
492a331
 
 
061d802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab4cf94
 
061d802
 
 
 
 
 
 
 
 
 
 
ab4cf94
 
061d802
35bcea0
061d802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492a331
061d802
 
 
 
 
 
 
ab4cf94
 
 
 
 
 
 
 
 
 
 
 
061d802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492a331
 
 
061d802
 
6ef117e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# 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 hexagonal 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.",
    "Map3": "Top-down view of a mystic forest map with lakes, dense forests, magical flora, and hex grids. Designed for tabletop gaming with clarity and strategic elements. Colors: light blue, green, purple, brown. Partial hexes on edges are black.",
    "Map4": "Top-down view of a medieval battlefield map with lakes, forests, magical fauna, and hex grids. 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, 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",
    "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
]