starline / utils.py
jonigata's picture
merge origin
f2a4883
import random
import string
import os
import requests
from tqdm import tqdm
def randomname(n):
randlst = [random.choice(string.ascii_letters + string.digits) for i in range(n)]
return ''.join(randlst)
def load_cn_model(model_dir):
folder = model_dir
file_name = 'diffusion_pytorch_model.safetensors'
url = "https://huggingface.co/kataragi/ControlNet-LineartXL/resolve/main/Katarag_lineartXL-fp16.safetensors"
file_path = os.path.join(folder, file_name)
if not os.path.exists(file_path):
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
with open(file_path, 'wb') as f, tqdm(
desc=file_name,
total=total_size,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for data in response.iter_content(chunk_size=1024):
size = f.write(data)
bar.update(size)
def load_cn_config(model_dir):
folder = model_dir
file_name = 'config.json'
url = "https://huggingface.co/mattyamonaca/controlnet_line2line_xl/resolve/main/config.json"
file_path = os.path.join(folder, file_name)
if not os.path.exists(file_path):
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
with open(file_path, 'wb') as f, tqdm(
desc=file_name,
total=total_size,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for data in response.iter_content(chunk_size=1024):
size = f.write(data)
bar.update(size)