CoolFace
Apppublic

raidensreturn/gen-tu39olwd

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
utils.py18 linesDownload Raw Back to root
1import random2from typing import Tuple3 4import torch5 6 7def prepare_generator(seed: int) -> Tuple[torch.Generator, int]:8    final_seed = seed9    if final_seed is None or final_seed < 0:10        final_seed = random.randint(0, 2**31 - 1)11    generator = torch.Generator(device="cuda" if torch.cuda.is_available() else "cpu").manual_seed(final_seed)12    return generator, final_seed13 14 15def sanitize_dimensions(width: int, height: int, max_width: int, max_height: int) -> Tuple[int, int]:16    width = max(256, min(max_width, int(width // 8 * 8)))17    height = max(256, min(max_height, int(height // 8 * 8)))18    return width, height