forked from Anning01/ComicTweets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_config.py
More file actions
73 lines (56 loc) · 1.98 KB
/
load_config.py
File metadata and controls
73 lines (56 loc) · 1.98 KB
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @author:anning
# @email:anningforchina@gmail.com
# @time:2024/04/06 11:33
# @file:load_config.py
import json
import os
import yaml
from aiofiles import os as aio_os
import aiofiles
# 自用配置文件路径
local_config_path = "local_config.yaml"
# 公共配置文件路径
public_config_path = "config.yaml"
# 尝试打开自用配置文件
if os.path.exists(local_config_path):
config_path = local_config_path
else:
# 如果自用配置文件不存在,使用公共配置文件
config_path = public_config_path
def get_yaml_config(config_path=config_path):
"""读取yaml配置文件"""
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
return config
def edit_yaml_config(data, config_path=config_path):
"""读取yaml配置文件"""
with open(config_path, 'w', encoding='utf-8') as file:
yaml.dump(data, file)
# 自用配置文件路径
local_stable_diffusion_path = "stable_diffusion.json"
# 公共配置文件路径
public_stable_diffusion_path = "local_stable_diffusion.json"
# 尝试打开自用配置文件
if os.path.exists(public_stable_diffusion_path):
stable_diffusion_path = public_stable_diffusion_path
else:
# 如果自用配置文件不存在,使用公共配置文件
stable_diffusion_path = local_stable_diffusion_path
def get_sd_config(config_path=stable_diffusion_path):
"""读取stable diffusion配置文件"""
with open(config_path, 'r', encoding='utf-8') as f:
config = json.load(f)
return config
async def print_tip(tip, blank_line=0):
"""打印提示文字和空行"""
blank = '\n' * blank_line if blank_line else ''
print('-' * 20, tip, '-' * 20, blank)
async def check_file_exists(file_path):
exists = await aio_os.path.exists(file_path)
return exists
async def get_file(file_path):
async with aiofiles.open(file_path, "r", encoding="utf-8") as f:
content = await f.read()
return content