Closed lalakiop closed 3 months ago
有必要吗...又没啥高频复杂操作
def select_json_files(): file_paths = filedialog.askopenfilenames(filetypes=[("JSON files", "*.json")]) if file_paths: return list(file_paths) else: return None
def init():
if not os.path.exists("config.json"):
config_data = {
"last_processed": 0,
"task_list": [],
"endpoint": "",
"api_type": 0,
"save_frequency": 100,
"shutdown": 0
}
with open("config.json", 'w') as file:
json.dump(config_data, file, indent=4)
# 读取配置文件
global api_type, endpoint, save_frequency, shutdown, task_list, start_index
with open('config.json', 'r', encoding='utf-8') as file:
data=json.load(file)
endpoint = data['endpoint']
api_type = data['api_type']
save_frequency = data['save_frequency']
shutdown = data['shutdown']
task_list = data['task_list']
start_index = data['last_processed']
# 读取api信息
if endpoint == '':
veri = input("请输入数字来选择部署类型(默认为本地部署):\n[0] 本地部署\n[1] kaggle部署\n")
if veri == "":
api_type = 0
else:
api_type = int(veri)
data['api_type'] = api_type
if api_type == 0 :
verurl = input("请输入Api地址(默认为http://127.0.0.1:8080/completion):\n")
if verurl == "" :
endpoint = "http://127.0.0.1:8080/completion"
else:
endpoint = verurl
data['endpoint'] = endpoint
else :
verurl = input("请输入Api地址(例如https://114-514-191-810.ngrok-free.app):\n")
if verurl == "" :
print("必须提供Api地址!")
sys.exit()
else :
endpoint = verurl+"/v1/chat/completions"
data['endpoint'] = endpoint
print("配置已保存到config.json,下次启动将默认加载")
# 读取任务列表,保存频率,自动关机信息
if task_list == []:
print("请选择需要翻译的 JSON 文件:")
selected_files = select_json_files()
if selected_files is None:
print("没有选择任何文件,程序退出。")
sys.exit()
else:
task_list = selected_files
else:
print(f"已加载任务列表{task_list},保存频率为{save_frequency},自动关机状态为{shutdown}")
# 保存配置
with open('config.json', 'w') as file:
json.dump(data, file, indent=4)
建议增加一个GUI,并打包成exe。这样可以使用GUI来选择要翻译的josn