save code

This commit is contained in:
xsl
2025-10-04 17:14:04 +08:00
parent 1fbb91eadb
commit 71ec26c7de
2 changed files with 51 additions and 16 deletions
+11 -8
View File
@@ -292,11 +292,11 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2,
return None, None, sex_girl, "cur gpu is busy, Shou not happen"
if tuodi:
print(f'开始换衣服 {change_tuodi_input} cloth_len:{cloth_len} cloth_short:{cloth_short} kuzi:{kuzi}')
print(f'开始换衣服 {change_tuodi_input} cloth_len:{cloth_len} cloth_short:{cloth_short}')
with open(f'{APP_ROOT}/{change_tuodi_input}', 'r', encoding='utf-8') as file:
prompt_text = file.read()
else:
print(f'开始换衣服 {change_only_name} cloth_len:{cloth_len} cloth_short:{cloth_short} kuzi:{kuzi}')
print(f'开始换衣服 {change_only_name} cloth_len:{cloth_len} cloth_short:{cloth_short}')
with open(f'{APP_ROOT}/{change_only_name}', 'r', encoding='utf-8') as file:
prompt_text = file.read()
@@ -509,7 +509,7 @@ def upload_to_oss(image_path, object_name=None):
def process_change_cloth(human_filename, cloth_filename, output_format, img_url, human_url, no2, tuodi, kuzi_url):
w,h = get_image_dimensions(f'{APP_ROOT}/../input/{human_filename}')
out_put_name, out_human_name, is_girl, msg = change(human_filename, cloth_filename, w, h, img_url, human_url, no2, tuodi, kuzi_url)
out_put_name, out_human_name, is_girl, msg = change(human_filename, cloth_filename, w, h, img_url, human_url, no2, tuodi)
if out_put_name == None:
print(f'Failed to change cloth {msg}')
return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200
@@ -540,8 +540,13 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
out_befor_kuzi_url = https_url
if kuzi_url:
output_path_name = os.path.join(f'{APP_ROOT}/../output', out_put_name)
output_path_name_input = os.path.join(f'{APP_ROOT}/../input', out_put_name)
shutil.copy(output_path_name, output_path_name_input)
kuzi_filename = save_image_from_url(kuzi_url)
kuzi_out_put_name = change_kuzi(human_filename, kuzi_filename)
kuzi_out_put_name, msg = change_kuzi(out_put_name, kuzi_filename)
image = Image.open(f'{APP_ROOT}/../output/{kuzi_out_put_name}')
jpg_name = kuzi_out_put_name.replace(".png", ".jpg")
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
@@ -558,7 +563,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
"ret":0,
"state": 0,
"msg":"success",
"second_step_datea":image_to_base64(out_befor_kuzi_url),
"second_step_data":image_to_base64(out_befor_kuzi_url),
"first_step_data":image_to_base64(out_human_jpg_path_name),
"is_girl":is_girl,
"data":image_to_base64(jpg_path_name)
@@ -644,12 +649,10 @@ def do_change_cloth():
tuodi = data['tuodi']
print(f"tuodi:{tuodi}")
kuzi_url = None
if 'kuzi_url' in data:
kuzi_url = data.get("kuzi_url")
kuzi_filename = save_image_from_url(kuzi_url)
print(f"要弄裤子 kuzi:{kuzi_url}")
try:
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2, tuodi, kuzi_url)
+40 -8
View File
@@ -96,17 +96,25 @@
<input type="file" id="clothInput" accept="image/*">
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
</div>
<br>
<div class="image-upload-box">
<h3>裤子图片</h3>
<input type="file" id="kuziInput" accept="image/*">
<img id="kuziPreview" class="image-preview" alt="裤子图片预览">
</div>
<br>
<div class="option-box">
<label>
<input type="checkbox" id="no2Checkbox"> 设置 no2 不要两步(一步完成)
</label>
<br>
<label>
<input type="checkbox" id="tuodiCheckbox"> 设置 tuodi(拖地)
</label>
<label>
<br>
<!-- <label>
<input type="checkbox" id="kuziCheckbox"> 设置 kuzi(裤子)
</label>
</label> -->
</div>
</div>
@@ -146,14 +154,28 @@
reader.readAsDataURL(file);
}
});
document.getElementById('kuziInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
const img = document.getElementById('kuziPreview');
img.src = event.target.result;
img.style.display = 'block';
};
reader.readAsDataURL(file);
}
});
// 提交处理
document.getElementById('submitBtn').addEventListener('click', function() {
const humanFile = document.getElementById('humanInput').files[0];
const clothFile = document.getElementById('clothInput').files[0];
const kuziFile = document.getElementById('kuziInput').files[0];
const no2 = document.getElementById("no2Checkbox").checked;
const tuodi = document.getElementById("tuodiCheckbox").checked;
const kuzi = document.getElementById("kuziCheckbox").checked;
if (!humanFile || !clothFile) {
alert('请同时选择人体图片和衣服图片!');
@@ -167,17 +189,25 @@
// 读取图片并转换为Base64(包含完整前缀)
Promise.all([
readFileAsDataURL(humanFile),
readFileAsDataURL(clothFile)
]).then(([humanDataURL, clothDataURL]) => {
readFileAsDataURL(clothFile),
kuziFile ? readFileAsDataURL(kuziFile) : Promise.resolve(null)
]).then(([humanDataURL, clothDataURL, kuziDataURL]) => {
// 准备请求数据
const data = {
human_img: humanDataURL, // 包含完整前缀的Base64
cloth_img: clothDataURL, // 包含完整前缀的Base64
output_format: "url",
no2: no2,
tuodi:tuodi,
kuzi:kuzi
tuodi:tuodi
};
if(kuziDataURL)
{
data.kuzi_img = kuziDataURL;
}
console.log("准备发送的数据:", data); // 调试用
@@ -209,6 +239,8 @@
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
<a href="${data.first_url}" target="_blank">${data.url}</a>
<p><img src="${data.first_url}" style="max-width: 100%; margin-top: 10px;"></p>
<a href="${data.second_url}" target="_blank">${data.url}</a>
<p><img src="${data.second_url}" style="max-width: 100%; margin-top: 10px;"></p>
`;
} else {
resultDiv.innerHTML = `