Skip to content

Commit 2a8e361

Browse files
Fix defaults
1 parent 1bb82a5 commit 2a8e361

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

examples/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ def save_result_image(resp_json):
4646
def handle_response(resp_json, timer):
4747
total_time = timer.get_elapsed_time()
4848

49-
if resp_json['output'] is not None and 'image' in resp_json['output']:
49+
output = resp_json.get('output', {})
50+
51+
if not output:
52+
print("No output found in the response.")
53+
54+
if 'image' in output:
5055
save_result_image(resp_json)
5156
else:
5257
print(json.dumps(resp_json, indent=4, default=str))

handler.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -335,29 +335,29 @@ def face_swap_api(job_id: str, job_input: dict):
335335
target_file.write(target_image)
336336

337337
try:
338-
logger.info(f'Source indexes: {job_input["source_indexes"]}', job_id)
339-
logger.info(f'Target indexes: {job_input["target_indexes"]}', job_id)
340-
logger.info(f'Background enhance: {job_input["background_enhance"]}', job_id)
341-
logger.info(f'Face Restoration: {job_input["face_restore"]}', job_id)
342-
logger.info(f'Face Upsampling: {job_input["face_upsample"]}', job_id)
343-
logger.info(f'Upscale: {job_input["upscale"]}', job_id)
344-
logger.info(f'Codeformer Fidelity: {job_input["codeformer_fidelity"]}', job_id)
345-
logger.info(f'Output Format: {job_input["output_format"]}', job_id)
346-
logger.info(f'Min Face Size: {job_input["min_face_size"]}', job_id)
338+
logger.info(f'Source indexes: {job_input.get("source_indexes", "-1")}', job_id)
339+
logger.info(f'Target indexes: {job_input.get("target_indexes", "-1")}', job_id)
340+
logger.info(f'Background enhance: {job_input.get("background_enhance", True)}', job_id)
341+
logger.info(f'Face Restoration: {job_input.get("face_restore", True)}', job_id)
342+
logger.info(f'Face Upsampling: {job_input.get("face_upsample", True)}', job_id)
343+
logger.info(f'Upscale: {job_input.get("upscale", 1)}', job_id)
344+
logger.info(f'Codeformer Fidelity: {job_input.get("codeformer_fidelity", 0.5)}', job_id)
345+
logger.info(f'Output Format: {job_input.get("output_format", "JPEG")}', job_id)
346+
logger.info(f'Min Face Size: {job_input.get("min_face_size", 0.0)}', job_id)
347347

348348
result_image = face_swap(
349349
job_id,
350350
source_image_path,
351351
target_image_path,
352-
job_input['source_indexes'],
353-
job_input['target_indexes'],
354-
job_input['background_enhance'],
355-
job_input['face_restore'],
356-
job_input['face_upsample'],
357-
job_input['upscale'],
358-
job_input['codeformer_fidelity'],
359-
job_input['output_format'],
360-
job_input['min_face_size']
352+
job_input.get('source_indexes', '-1'),
353+
job_input.get('target_indexes', '-1'),
354+
job_input.get('background_enhance', True),
355+
job_input.get('face_restore', True),
356+
job_input.get('face_upsample', True),
357+
job_input.get('upscale', 1),
358+
job_input.get('codeformer_fidelity', 0.5),
359+
job_input.get('output_format', 'JPEG'),
360+
job_input.get('min_face_size', 0.0)
361361
)
362362

363363
clean_up_temporary_files(source_image_path, target_image_path)

0 commit comments

Comments
 (0)