Spaces:
Build error
Build error
File size: 2,533 Bytes
b6e0092 |
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 |
import os
import os.path as osp
import cv2
import numpy as np
import numpy.random as npr
import torch
import torch.nn.functional as F
import torchvision.transforms as tvtrans
import PIL.Image
from tqdm import tqdm
from PIL import Image
import copy
import json
from collections import OrderedDict
#######
# css #
#######
css_empty = ""
css_version_4_11_0 = """
#customized_imbox {
min-height: 450px;
max-height: 450px;
}
#customized_imbox>div[data-testid="image"] {
min-height: 450px;
}
#customized_imbox>div[data-testid="image"]>span[data-testid="source-select"] {
max-height: 0px;
}
#customized_imbox>div[data-testid="image"]>span[data-testid="source-select"]>button {
max-height: 0px;
}
#customized_imbox>div[data-testid="image"]>div.upload-container>div.image-frame>img {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
width: unset;
height: unset;
max-height: 450px;
}
#customized_imbox>div.unpadded_box {
min-height: 450px;
}
#myinst {
font-size: 0.8rem;
margin: 0rem;
color: #6B7280;
}
#maskinst {
text-align: justify;
min-width: 1200px;
}
#maskinst>img {
min-width:399px;
max-width:450px;
vertical-align: top;
display: inline-block;
}
#maskinst:after {
content: "";
width: 100%;
display: inline-block;
}
"""
##########
# helper #
##########
def highlight_print(info):
print('')
print(''.join(['#']*(len(info)+4)))
print('# '+info+' #')
print(''.join(['#']*(len(info)+4)))
print('')
def auto_dropdown(name, choices_od, value):
import gradio as gr
option_list = [pi for pi in choices_od.keys()]
return gr.Dropdown(label=name, choices=option_list, value=value)
def load_sd_from_file(target):
if osp.splitext(target)[-1] == '.ckpt':
sd = torch.load(target, map_location='cpu')['state_dict']
elif osp.splitext(target)[-1] == '.pth':
sd = torch.load(target, map_location='cpu')
elif osp.splitext(target)[-1] == '.safetensors':
from safetensors.torch import load_file as stload
sd = OrderedDict(stload(target, device='cpu'))
else:
assert False, "File type must be .ckpt or .pth or .safetensors"
return sd
def torch_to_numpy(x):
return x.detach().to('cpu').numpy()
if __name__ == '__main__':
pass
|