save code
This commit is contained in:
+10
-7
@@ -513,10 +513,10 @@ def image_to_base64(file_path, with_head = True):
|
|||||||
|
|
||||||
def upload_to_oss(image_path, object_name=None):
|
def upload_to_oss(image_path, object_name=None):
|
||||||
# 配置信息(替换为你的实际信息)
|
# 配置信息(替换为你的实际信息)
|
||||||
access_key_id = 'LTAI5tB9t2RH6f1drSLvVLLZ'
|
access_key_id = 'LTAI5tGp1sLzedqxihcNC1eb'
|
||||||
access_key_secret = '91uzPI1RAFHN7n3Y6TJDGFP8w0dG1R'
|
access_key_secret = 'IFZE1b8YYreCP6zfA6GaZ9uBT678qO'
|
||||||
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
||||||
bucket_name = 'llyz'
|
bucket_name = 'xiangsilian'
|
||||||
|
|
||||||
# 创建Bucket实例
|
# 创建Bucket实例
|
||||||
auth = oss2.Auth(access_key_id, access_key_secret)
|
auth = oss2.Auth(access_key_id, access_key_secret)
|
||||||
@@ -615,7 +615,7 @@ def process_change_banana(human_filename, cloth_filename, output_format):
|
|||||||
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
|
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
|
||||||
image.save(jpg_path_name, quality=90)
|
image.save(jpg_path_name, quality=90)
|
||||||
upload_to_oss(jpg_path_name, jpg_name)
|
upload_to_oss(jpg_path_name, jpg_name)
|
||||||
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
||||||
|
|
||||||
if img_data:
|
if img_data:
|
||||||
if 'base64' in output_format:
|
if 'base64' in output_format:
|
||||||
@@ -658,7 +658,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
out_human_jpg_path_name = f'{APP_ROOT}/static/imgs/{out_human_jpg_name}'
|
out_human_jpg_path_name = f'{APP_ROOT}/static/imgs/{out_human_jpg_name}'
|
||||||
out_human_image.save(out_human_jpg_path_name, quality=90)
|
out_human_image.save(out_human_jpg_path_name, quality=90)
|
||||||
upload_to_oss(out_human_jpg_path_name, out_human_jpg_name) # 第二个参数可选,指定OSS上的路径
|
upload_to_oss(out_human_jpg_path_name, out_human_jpg_name) # 第二个参数可选,指定OSS上的路径
|
||||||
out_human_https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{out_human_jpg_name}'
|
out_human_https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{out_human_jpg_name}'
|
||||||
print(f"生成的第一步图片 HTTPS URL: {out_human_https_url}")
|
print(f"生成的第一步图片 HTTPS URL: {out_human_https_url}")
|
||||||
|
|
||||||
image = Image.open(f'{APP_ROOT}/../output/{out_put_name}')
|
image = Image.open(f'{APP_ROOT}/../output/{out_put_name}')
|
||||||
@@ -668,7 +668,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
|
|
||||||
|
|
||||||
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
||||||
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
||||||
print(f"生成的HTTPS URL: {https_url}")
|
print(f"生成的HTTPS URL: {https_url}")
|
||||||
|
|
||||||
out_befor_kuzi_url = https_url
|
out_befor_kuzi_url = https_url
|
||||||
@@ -686,7 +686,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
image.save(jpg_path_name, quality=90)
|
image.save(jpg_path_name, quality=90)
|
||||||
|
|
||||||
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
||||||
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
||||||
print(f"生成的加上换裤子的 HTTPS URL: {https_url}")
|
print(f"生成的加上换裤子的 HTTPS URL: {https_url}")
|
||||||
|
|
||||||
|
|
||||||
@@ -755,6 +755,8 @@ def do_change_cloth():
|
|||||||
"""从 URL 下载图片"""
|
"""从 URL 下载图片"""
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
||||||
|
print(f"do_change_cloth input data:{data}")
|
||||||
|
|
||||||
human_url = data.get("human_url")
|
human_url = data.get("human_url")
|
||||||
|
|
||||||
human_filename = save_image_from_url(human_url)
|
human_filename = save_image_from_url(human_url)
|
||||||
@@ -892,6 +894,7 @@ def change_cloth():
|
|||||||
def change_cloth_base64():
|
def change_cloth_base64():
|
||||||
# 获取参数
|
# 获取参数
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
print(f"change_cloth_base64 input data:{data}")
|
||||||
if not data:
|
if not data:
|
||||||
return jsonify({"ret":-1, "state":-1, 'msg': 'No JSON data provided'}), 400
|
return jsonify({"ret":-1, "state":-1, 'msg': 'No JSON data provided'}), 400
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import logging
|
|||||||
|
|
||||||
QUEUE_NAME = 'task_queue'
|
QUEUE_NAME = 'task_queue'
|
||||||
# 配置
|
# 配置
|
||||||
REDIS_HOST = '192.168.101.118'
|
REDIS_HOST = '127.0.0.1'#'192.168.101.118'
|
||||||
REDIS_PORT = 6379
|
REDIS_PORT = 6379
|
||||||
REDIS_DB = 0
|
REDIS_DB = 0
|
||||||
DEFAULT_TIMEOUT = (60*20)
|
DEFAULT_TIMEOUT = (60*20)
|
||||||
|
|||||||
+6
-4
@@ -255,10 +255,10 @@ def image_to_base64(file_path, mime_type=None):
|
|||||||
|
|
||||||
def upload_to_oss(image_path, object_name=None):
|
def upload_to_oss(image_path, object_name=None):
|
||||||
# 配置信息(替换为你的实际信息)
|
# 配置信息(替换为你的实际信息)
|
||||||
access_key_id = 'LTAI5tB9t2RH6f1drSLvVLLZ'
|
access_key_id = 'LTAI5tGp1sLzedqxihcNC1eb'
|
||||||
access_key_secret = '91uzPI1RAFHN7n3Y6TJDGFP8w0dG1R'
|
access_key_secret = 'IFZE1b8YYreCP6zfA6GaZ9uBT678qO'
|
||||||
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
||||||
bucket_name = 'llyz'
|
bucket_name = 'xiangsilian'
|
||||||
|
|
||||||
# 创建Bucket实例
|
# 创建Bucket实例
|
||||||
auth = oss2.Auth(access_key_id, access_key_secret)
|
auth = oss2.Auth(access_key_id, access_key_secret)
|
||||||
@@ -300,7 +300,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
|
|
||||||
|
|
||||||
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
|
||||||
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/{jpg_name}'
|
||||||
print(f"生成的HTTPS URL: {https_url}")
|
print(f"生成的HTTPS URL: {https_url}")
|
||||||
|
|
||||||
if 'base64' in output_format:
|
if 'base64' in output_format:
|
||||||
@@ -394,6 +394,7 @@ def save_image_from_url(image_url):
|
|||||||
def change_cloth():
|
def change_cloth():
|
||||||
"""从 URL 下载图片"""
|
"""从 URL 下载图片"""
|
||||||
data = request.json
|
data = request.json
|
||||||
|
print(f"change_cloth data: {data}")
|
||||||
|
|
||||||
is_generated = data.get("is_generated")
|
is_generated = data.get("is_generated")
|
||||||
# if not is_generated:
|
# if not is_generated:
|
||||||
@@ -406,6 +407,7 @@ def change_cloth():
|
|||||||
if not human_url:
|
if not human_url:
|
||||||
return jsonify({"error": "Missing 'human_url' parameter"}), 400
|
return jsonify({"error": "Missing 'human_url' parameter"}), 400
|
||||||
|
|
||||||
|
|
||||||
human_filename = save_image_from_url(human_url)
|
human_filename = save_image_from_url(human_url)
|
||||||
if not human_filename:
|
if not human_filename:
|
||||||
return jsonify({"error": "Failed to download or save human image"}), 500
|
return jsonify({"error": "Failed to download or save human image"}), 500
|
||||||
|
|||||||
+4
-4
@@ -2,10 +2,10 @@ import oss2
|
|||||||
|
|
||||||
def upload_to_oss(image_path, object_name=None):
|
def upload_to_oss(image_path, object_name=None):
|
||||||
# 配置信息(替换为你的实际信息)
|
# 配置信息(替换为你的实际信息)
|
||||||
access_key_id = 'LTAI5tB9t2RH6f1drSLvVLLZ'
|
access_key_id = 'LTAI5tGp1sLzedqxihcNC1eb'
|
||||||
access_key_secret = '91uzPI1RAFHN7n3Y6TJDGFP8w0dG1R'
|
access_key_secret = 'IFZE1b8YYreCP6zfA6GaZ9uBT678qO'
|
||||||
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
endpoint = 'oss-cn-beijing.aliyuncs.com' # 替换为你的Endpoint
|
||||||
bucket_name = 'llyz'
|
bucket_name = 'xiangsilian'
|
||||||
|
|
||||||
# 创建Bucket实例
|
# 创建Bucket实例
|
||||||
auth = oss2.Auth(access_key_id, access_key_secret)
|
auth = oss2.Auth(access_key_id, access_key_secret)
|
||||||
@@ -34,5 +34,5 @@ def upload_to_oss(image_path, object_name=None):
|
|||||||
# 使用示例
|
# 使用示例
|
||||||
image_path = '/home/xsl/code/ComfyUI/change_cloth/girl8010.jpg' # 本地图片路径
|
image_path = '/home/xsl/code/ComfyUI/change_cloth/girl8010.jpg' # 本地图片路径
|
||||||
upload_to_oss(image_path, 'girl8011.jpg') # 第二个参数可选,指定OSS上的路径
|
upload_to_oss(image_path, 'girl8011.jpg') # 第二个参数可选,指定OSS上的路径
|
||||||
https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/girl8011.jpg'
|
https_url = f'https://xiangsilian.oss-cn-beijing.aliyuncs.com/girl8011.jpg'
|
||||||
print(f"生成的HTTPS URL: {https_url}")
|
print(f"生成的HTTPS URL: {https_url}")
|
||||||
|
|||||||
+186
@@ -0,0 +1,186 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>图片处理工具</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
.form-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
input[type="file"], input[type="text"] {
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
padding: 10px 15px;
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
.preview {
|
||||||
|
margin-top: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
.preview-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.preview-item img {
|
||||||
|
max-width: 200px;
|
||||||
|
max-height: 200px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
#status {
|
||||||
|
margin-top: 20px;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.success {
|
||||||
|
background-color: #dff0d8;
|
||||||
|
color: #3c763d;
|
||||||
|
}
|
||||||
|
.error {
|
||||||
|
background-color: #f2dede;
|
||||||
|
color: #a94442;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>图片处理工具</h1>
|
||||||
|
<div class="container">
|
||||||
|
<form id="imageForm">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="fileUpload">上传图片:</label>
|
||||||
|
<input type="file" id="fileUpload" name="file" accept="image/*" required>
|
||||||
|
<div class="preview">
|
||||||
|
<div class="preview-item">
|
||||||
|
<span>上传的图片预览:</span>
|
||||||
|
<img id="uploadPreview" src="#" alt="上传的图片预览" style="display: none;">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="clothImgUrl">服装图片URL:</label>
|
||||||
|
<input type="text" id="clothImgUrl" name="cloth_img"
|
||||||
|
value="http://112.126.94.241:18888/static/imgs/cloth_20250713_092536_279335d2.jpg"
|
||||||
|
placeholder="输入服装图片的URL" required>
|
||||||
|
<div class="preview">
|
||||||
|
<div class="preview-item">
|
||||||
|
<span>URL图片预览:</span>
|
||||||
|
<img id="urlPreview" src="http://112.126.94.241:18888/static/imgs/cloth_20250713_092536_279335d2.jpg"
|
||||||
|
alt="URL图片预览" onerror="this.style.display='none'">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit">提交处理</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div id="status"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 上传图片预览
|
||||||
|
document.getElementById('fileUpload').addEventListener('change', function(e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function(event) {
|
||||||
|
const preview = document.getElementById('uploadPreview');
|
||||||
|
preview.src = event.target.result;
|
||||||
|
preview.style.display = 'block';
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// URL图片预览
|
||||||
|
document.getElementById('clothImgUrl').addEventListener('input', function(e) {
|
||||||
|
const url = e.target.value;
|
||||||
|
if (url) {
|
||||||
|
const preview = document.getElementById('urlPreview');
|
||||||
|
preview.src = url;
|
||||||
|
preview.style.display = 'block';
|
||||||
|
|
||||||
|
// 检查图片是否能加载
|
||||||
|
preview.onerror = function() {
|
||||||
|
preview.alt = "无法加载图片";
|
||||||
|
preview.src = "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 表单提交
|
||||||
|
document.getElementById('imageForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const statusDiv = document.getElementById('status');
|
||||||
|
statusDiv.textContent = "正在提交...";
|
||||||
|
statusDiv.className = "";
|
||||||
|
|
||||||
|
const formData = new FormData(this);
|
||||||
|
const apiUrl = "http://47.94.244.112:19001/process-image";
|
||||||
|
|
||||||
|
fetch(apiUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('网络响应不正常');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
statusDiv.textContent = "提交成功!";
|
||||||
|
statusDiv.className = "success";
|
||||||
|
console.log("成功:", data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
statusDiv.textContent = "提交失败: " + error.message;
|
||||||
|
statusDiv.className = "error";
|
||||||
|
console.error("错误:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 初始加载时检查默认URL图片
|
||||||
|
window.addEventListener('load', function() {
|
||||||
|
const preview = document.getElementById('urlPreview');
|
||||||
|
preview.onerror = function() {
|
||||||
|
preview.alt = "无法加载默认图片";
|
||||||
|
preview.src = "";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user