初始化换发型项目:3个微服务代码 + 部署脚本

包含:
- hair_service_sd: 换发型/换发色算法服务 (端口 8801)
- photo_service: LoRA 训练调度服务 (端口 32678)
- stable-diffusion-webui: SD WebUI 推理服务 (端口 57860)
- kohya_ss_home: 训练环境代码
- meidaojia: 监控测试脚本
- setup.sh: 一键部署脚本 (conda环境恢复 + 配置生成 + 完整性检查)
- start_all_services.sh: 启动3个服务
- configure.ini.template: 路径模板化 (BASE_DIR自动推导)
- conda_envs/py310.yml: py310 环境定义

大文件 (weights/, models/, data/, conda_envs/*.tar.gz 等) 通过 .gitignore 排除,
由网盘单独上传。
This commit is contained in:
colomi
2026-07-11 18:11:49 +08:00
commit 0eb61f3e60
628 changed files with 120882 additions and 0 deletions
+128
View File
@@ -0,0 +1,128 @@
import threading
import requests
import json
import base64
import time
import random
# url = 'http://xiangsilian.com:18801/api/swapHair/v1'
url = 'https://779460252262853-http-8801.northwest1.gpugeek.com:8443/api/swapHair/v1'
headers = {'Content-Type': 'application/json'}
data = {
#"hair_id": "1907651680352395265",
"hair_id": "1954538119216013313",
"task_id": "3455643521235",
"user_img_path": "https://cdn.meidaojia.com/ZoeFiles/testuser_8.JPG",
"is_hr": "false",
"output_format": "base64"
}
def image_to_base64(file_path, mime_type=None):
"""
将图片文件转换为带Base64前缀的Data URI字符串
参数:
file_path (str): 图片文件路径
mime_type (str): 可选,指定MIME类型。如果为None,则根据文件扩展名自动判断
返回:
str: 带Base64前缀的Data URI字符串
"""
# 如果没有指定MIME类型,根据文件扩展名推断
if mime_type is None:
extension = file_path.split('.')[-1].lower()
mime_types = {
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'png': 'image/png',
'gif': 'image/gif',
'webp': 'image/webp',
'bmp': 'image/bmp'
}
mime_type = mime_types.get(extension, 'application/octet-stream')
# 读取文件内容并编码为Base64
with open(file_path, 'rb') as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
# 组合成Data URI格式
return f"data:{mime_type};base64,{encoded_string}"
img64_str = image_to_base64("wertwert.jpg")
data['user_img_path'] = img64_str
responses = []
lock = threading.Lock()
send_index = 0
def send_request(start_time):
try:
sleep_time = start_time
time.sleep(sleep_time)
global send_index
send_data = data
response = requests.post(url, headers=headers, json=send_data)
with lock: # 加锁,防止多线程同时修改 responses
responses.append(response)
except Exception as e:
with lock:
responses.append({"error": str(e)})
threads = []
num_requests = 1
time_start = time.time()
start_time = 0
for _ in range(num_requests):
start_time = 0
t = threading.Thread(target=send_request, args=(start_time,))
t.start()
threads.append(t)
for t in threads:
t.join()
end_time = time.time()
total_time = (end_time - time_start)
qps = num_requests/total_time
print(f"num_requests:{num_requests} total_time:{total_time} qps:{qps}")
import base64
import os
def save_base64_image(base64_str, filename):
"""
将 Base64 编码的图片字符串保存为本地 JPG 文件。
:param base64_str: Base64 编码的图片字符串(可能包含 data:image/jpeg;base64, 前缀)
:param filename: 保存的文件名(例如 'image.jpg'
"""
# 如果包含 data URL 前缀,去掉它
if base64_str.startswith("data:image"):
base64_str = base64_str.split(",", 1)[1]
try:
image_data = base64.b64decode(base64_str)
with open(filename, "wb") as f:
f.write(image_data)
print(f"图片已保存为 {filename}")
except Exception as e:
print(f"保存图片失败: {e}")
# 打印所有响应
for i, resp in enumerate(responses, 1):
print(f"请求 {i} 结果: {resp.status_code, resp.text[:128]}")
json_obj = json.loads(resp.text)
data_string = json_obj['data']
save_base64_image(data_string, f"response_{i}.jpg")