save code
This commit is contained in:
+11
-8
@@ -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"
|
return None, None, sex_girl, "cur gpu is busy, Shou not happen"
|
||||||
|
|
||||||
if tuodi:
|
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:
|
with open(f'{APP_ROOT}/{change_tuodi_input}', 'r', encoding='utf-8') as file:
|
||||||
prompt_text = file.read()
|
prompt_text = file.read()
|
||||||
else:
|
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:
|
with open(f'{APP_ROOT}/{change_only_name}', 'r', encoding='utf-8') as file:
|
||||||
prompt_text = file.read()
|
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):
|
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}')
|
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:
|
if out_put_name == None:
|
||||||
print(f'Failed to change cloth {msg}')
|
print(f'Failed to change cloth {msg}')
|
||||||
return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200
|
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
|
out_befor_kuzi_url = https_url
|
||||||
if kuzi_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_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}')
|
image = Image.open(f'{APP_ROOT}/../output/{kuzi_out_put_name}')
|
||||||
jpg_name = kuzi_out_put_name.replace(".png", ".jpg")
|
jpg_name = kuzi_out_put_name.replace(".png", ".jpg")
|
||||||
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
|
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,
|
"ret":0,
|
||||||
"state": 0,
|
"state": 0,
|
||||||
"msg":"success",
|
"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),
|
"first_step_data":image_to_base64(out_human_jpg_path_name),
|
||||||
"is_girl":is_girl,
|
"is_girl":is_girl,
|
||||||
"data":image_to_base64(jpg_path_name)
|
"data":image_to_base64(jpg_path_name)
|
||||||
@@ -644,13 +649,11 @@ def do_change_cloth():
|
|||||||
tuodi = data['tuodi']
|
tuodi = data['tuodi']
|
||||||
print(f"tuodi:{tuodi}")
|
print(f"tuodi:{tuodi}")
|
||||||
|
|
||||||
|
kuzi_url = None
|
||||||
if 'kuzi_url' in data:
|
if 'kuzi_url' in data:
|
||||||
kuzi_url = data.get("kuzi_url")
|
kuzi_url = data.get("kuzi_url")
|
||||||
kuzi_filename = save_image_from_url(kuzi_url)
|
|
||||||
print(f"要弄裤子 kuzi:{kuzi_url}")
|
print(f"要弄裤子 kuzi:{kuzi_url}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2, tuodi, kuzi_url)
|
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2, tuodi, kuzi_url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
+40
-8
@@ -96,17 +96,25 @@
|
|||||||
<input type="file" id="clothInput" accept="image/*">
|
<input type="file" id="clothInput" accept="image/*">
|
||||||
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
|
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
|
||||||
</div>
|
</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">
|
<div class="option-box">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="no2Checkbox"> 设置 no2 不要两步(一步完成)
|
<input type="checkbox" id="no2Checkbox"> 设置 no2 不要两步(一步完成)
|
||||||
</label>
|
</label>
|
||||||
|
<br>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="tuodiCheckbox"> 设置 tuodi(拖地)
|
<input type="checkbox" id="tuodiCheckbox"> 设置 tuodi(拖地)
|
||||||
</label>
|
</label>
|
||||||
|
<br>
|
||||||
<label>
|
<!-- <label>
|
||||||
<input type="checkbox" id="kuziCheckbox"> 设置 kuzi(裤子)
|
<input type="checkbox" id="kuziCheckbox"> 设置 kuzi(裤子)
|
||||||
</label>
|
</label> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -147,13 +155,27 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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() {
|
document.getElementById('submitBtn').addEventListener('click', function() {
|
||||||
const humanFile = document.getElementById('humanInput').files[0];
|
const humanFile = document.getElementById('humanInput').files[0];
|
||||||
const clothFile = document.getElementById('clothInput').files[0];
|
const clothFile = document.getElementById('clothInput').files[0];
|
||||||
|
const kuziFile = document.getElementById('kuziInput').files[0];
|
||||||
const no2 = document.getElementById("no2Checkbox").checked;
|
const no2 = document.getElementById("no2Checkbox").checked;
|
||||||
const tuodi = document.getElementById("tuodiCheckbox").checked;
|
const tuodi = document.getElementById("tuodiCheckbox").checked;
|
||||||
const kuzi = document.getElementById("kuziCheckbox").checked;
|
|
||||||
|
|
||||||
if (!humanFile || !clothFile) {
|
if (!humanFile || !clothFile) {
|
||||||
alert('请同时选择人体图片和衣服图片!');
|
alert('请同时选择人体图片和衣服图片!');
|
||||||
@@ -167,18 +189,26 @@
|
|||||||
// 读取图片并转换为Base64(包含完整前缀)
|
// 读取图片并转换为Base64(包含完整前缀)
|
||||||
Promise.all([
|
Promise.all([
|
||||||
readFileAsDataURL(humanFile),
|
readFileAsDataURL(humanFile),
|
||||||
readFileAsDataURL(clothFile)
|
readFileAsDataURL(clothFile),
|
||||||
]).then(([humanDataURL, clothDataURL]) => {
|
kuziFile ? readFileAsDataURL(kuziFile) : Promise.resolve(null)
|
||||||
|
]).then(([humanDataURL, clothDataURL, kuziDataURL]) => {
|
||||||
|
|
||||||
|
|
||||||
// 准备请求数据
|
// 准备请求数据
|
||||||
const data = {
|
const data = {
|
||||||
human_img: humanDataURL, // 包含完整前缀的Base64
|
human_img: humanDataURL, // 包含完整前缀的Base64
|
||||||
cloth_img: clothDataURL, // 包含完整前缀的Base64
|
cloth_img: clothDataURL, // 包含完整前缀的Base64
|
||||||
output_format: "url",
|
output_format: "url",
|
||||||
no2: no2,
|
no2: no2,
|
||||||
tuodi:tuodi,
|
tuodi:tuodi
|
||||||
kuzi:kuzi
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(kuziDataURL)
|
||||||
|
{
|
||||||
|
data.kuzi_img = kuziDataURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
console.log("准备发送的数据:", data); // 调试用
|
console.log("准备发送的数据:", data); // 调试用
|
||||||
|
|
||||||
// 调用API
|
// 调用API
|
||||||
@@ -209,6 +239,8 @@
|
|||||||
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
|
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
|
||||||
<a href="${data.first_url}" target="_blank">${data.url}</a>
|
<a href="${data.first_url}" target="_blank">${data.url}</a>
|
||||||
<p><img src="${data.first_url}" style="max-width: 100%; margin-top: 10px;"></p>
|
<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 {
|
} else {
|
||||||
resultDiv.innerHTML = `
|
resultDiv.innerHTML = `
|
||||||
|
|||||||
Reference in New Issue
Block a user