Add gen_latest_pic endpoint to retrieve the latest openpose image

This commit is contained in:
Kenny Cheng 2025-10-10 20:13:56 +08:00
parent ca9a891921
commit 4c51449257
1 changed files with 36 additions and 0 deletions

36
app.py
View File

@ -52,6 +52,42 @@ def gen_group_pic():
else: else:
return jsonify({"status": "error", "message": "Request must be JSON"}), 415 return jsonify({"status": "error", "message": "Request must be JSON"}), 415
@app.route('/gen_latest_pic', methods=['POST'])
def gen_latest_pic():
if request.is_json:
data = request.get_json()
base_image = base64.b64decode(data['base_image'])
pid = data.get('pid', 'default_user') # Use provided pid or default
if not base_image:
return jsonify({"status": "error", "message": "Missing data"}), 422
# Get the latest created openpose image from output directory
import os
import glob
output_dir = 'output'
# Search for all openpose output images
image_patterns = [
os.path.join(output_dir, 'body_pose_output*.png'),
os.path.join(output_dir, 'body_pose_output_multi*.png')
]
all_images = []
for pattern in image_patterns:
all_images.extend(glob.glob(pattern))
if not all_images:
return jsonify({"status": "error", "message": "No openpose images found in output directory"}), 404
# Get the latest file by modification time
openpose_image_path = max(all_images, key=os.path.getmtime)
gen_group_pic_prompt(openpose_image_path, base_image, pid, opg.server_address)
return jsonify({"status": "success", "message": "Data received"}), 201
else:
return jsonify({"status": "error", "message": "Request must be JSON"}), 415
def gen_fencer_prompt(openpose_image_path, pid, comfyUI_address): def gen_fencer_prompt(openpose_image_path, pid, comfyUI_address):