From cc609b4d8715ea9f6fa893f67b97e46c1858dde5 Mon Sep 17 00:00:00 2001 From: Bubbliiiing <47347516+bubbliiiing@users.noreply.github.com> Date: Wed, 30 Apr 2025 10:55:17 +0800 Subject: [PATCH] Fix bug in api (#192) * Fix bug in api * Fix bug in api --- examples/cogvideox_fun/post_infer.py | 2 ++ examples/cogvideox_fun/post_infer_queue.py | 2 ++ examples/wan2.1/post_infer.py | 2 ++ examples/wan2.1/post_infer_queue.py | 2 ++ examples/wan2.1/post_infer_queue_i2v.py | 7 ++++--- examples/wan2.1_fun/post_infer.py | 2 ++ examples/wan2.1_fun/post_infer_queue.py | 2 ++ examples/wan2.1_fun/post_infer_queue_i2v.py | 6 ++++-- examples/wan2.1_fun/post_infer_queue_v2v_control.py | 6 ++++-- videox_fun/api/api.py | 4 ++-- videox_fun/api/api_multi_nodes.py | 6 +++--- 11 files changed, 29 insertions(+), 12 deletions(-) diff --git a/examples/cogvideox_fun/post_infer.py b/examples/cogvideox_fun/post_infer.py index 239848c..20cd09e 100755 --- a/examples/cogvideox_fun/post_infer.py +++ b/examples/cogvideox_fun/post_infer.py @@ -64,6 +64,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) data = post_r.content.decode('utf-8') diff --git a/examples/cogvideox_fun/post_infer_queue.py b/examples/cogvideox_fun/post_infer_queue.py index db1b243..0791750 100755 --- a/examples/cogvideox_fun/post_infer_queue.py +++ b/examples/cogvideox_fun/post_infer_queue.py @@ -45,6 +45,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers diff --git a/examples/wan2.1/post_infer.py b/examples/wan2.1/post_infer.py index 7cc84c7..a002457 100755 --- a/examples/wan2.1/post_infer.py +++ b/examples/wan2.1/post_infer.py @@ -61,6 +61,8 @@ def post_infer( # Initialize session and set headers session = requests.session() + if url[-1] == "/": + url = url[:-1] session.headers.update({"Authorization": POST_TOKEN}) # Send POST request diff --git a/examples/wan2.1/post_infer_queue.py b/examples/wan2.1/post_infer_queue.py index 2145f90..0de7eb0 100755 --- a/examples/wan2.1/post_infer_queue.py +++ b/examples/wan2.1/post_infer_queue.py @@ -60,6 +60,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers diff --git a/examples/wan2.1/post_infer_queue_i2v.py b/examples/wan2.1/post_infer_queue_i2v.py index 659aab1..585fd7d 100755 --- a/examples/wan2.1/post_infer_queue_i2v.py +++ b/examples/wan2.1/post_infer_queue_i2v.py @@ -36,10 +36,10 @@ def post_infer( if start_image: try: if not start_image.startswith("http"): - image = Image.open(start_image) + image = Image.open(start_image).convert("RGB") # 将图片转换为 Base64 编码 buffered = BytesIO() - image.save(buffered, format=image.format) + image.save(buffered, format="JPEG") start_image = base64.b64encode(buffered.getvalue()).decode('utf-8') except Exception as e: print(f"Error processing start_image: {e}") @@ -76,6 +76,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers @@ -106,7 +108,6 @@ def post_infer( data = get_r.content.decode('utf-8') return data - if __name__ == '__main__': # initiate time time_start = time.time() diff --git a/examples/wan2.1_fun/post_infer.py b/examples/wan2.1_fun/post_infer.py index 9659c76..0493c9b 100755 --- a/examples/wan2.1_fun/post_infer.py +++ b/examples/wan2.1_fun/post_infer.py @@ -64,6 +64,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) data = post_r.content.decode('utf-8') diff --git a/examples/wan2.1_fun/post_infer_queue.py b/examples/wan2.1_fun/post_infer_queue.py index 6ba1e66..e6e89b6 100755 --- a/examples/wan2.1_fun/post_infer_queue.py +++ b/examples/wan2.1_fun/post_infer_queue.py @@ -60,6 +60,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers diff --git a/examples/wan2.1_fun/post_infer_queue_i2v.py b/examples/wan2.1_fun/post_infer_queue_i2v.py index 8c41607..cfb9a90 100755 --- a/examples/wan2.1_fun/post_infer_queue_i2v.py +++ b/examples/wan2.1_fun/post_infer_queue_i2v.py @@ -36,10 +36,10 @@ def post_infer( if start_image: try: if not start_image.startswith("http"): - image = Image.open(start_image) + image = Image.open(start_image).convert("RGB") # 将图片转换为 Base64 编码 buffered = BytesIO() - image.save(buffered, format=image.format) + image.save(buffered, format="JPEG") start_image = base64.b64encode(buffered.getvalue()).decode('utf-8') except Exception as e: print(f"Error processing start_image: {e}") @@ -76,6 +76,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers diff --git a/examples/wan2.1_fun/post_infer_queue_v2v_control.py b/examples/wan2.1_fun/post_infer_queue_v2v_control.py index 92cd0bc..99e6c85 100755 --- a/examples/wan2.1_fun/post_infer_queue_v2v_control.py +++ b/examples/wan2.1_fun/post_infer_queue_v2v_control.py @@ -49,10 +49,10 @@ def post_infer( if ref_image: try: if not ref_image.startswith("http"): - image = Image.open(ref_image) + image = Image.open(ref_image).convert("RGB") # 将图片转换为 Base64 编码 buffered = BytesIO() - image.save(buffered, format=image.format) + image.save(buffered, format="JPEG") ref_image = base64.b64encode(buffered.getvalue()).decode('utf-8') except Exception as e: print(f"Error processing ref_image: {e}") @@ -90,6 +90,8 @@ def post_infer( session.headers.update({"Authorization": POST_TOKEN}) # Send POST request + if url[-1] == "/": + url = url[:-1] post_r = session.post(f'{url}/videox_fun/infer_forward', data=datas, timeout=timeout) # Extract request ID from POST response headers diff --git a/videox_fun/api/api.py b/videox_fun/api/api.py index ef31740..1eb0b89 100755 --- a/videox_fun/api/api.py +++ b/videox_fun/api/api.py @@ -212,9 +212,9 @@ def infer_forward_api(_: gr.Blocks, app: FastAPI, controller): torch.cuda.ipc_collect() save_sample_path = "" comment = f"Error. error information is {str(e)}" - return {"message": comment} + return {"message": comment, "save_sample_path": None, "base64_encoding": None} if save_sample_path != "": return {"message": comment, "save_sample_path": save_sample_path, "base64_encoding": encode_file_to_base64(save_sample_path)} else: - return {"message": comment, "save_sample_path": save_sample_path} \ No newline at end of file + return {"message": comment, "save_sample_path": save_sample_path, "base64_encoding": None} \ No newline at end of file diff --git a/videox_fun/api/api_multi_nodes.py b/videox_fun/api/api_multi_nodes.py index dd61e40..8d54b61 100755 --- a/videox_fun/api/api_multi_nodes.py +++ b/videox_fun/api/api_multi_nodes.py @@ -161,18 +161,18 @@ if ray is not None: torch.cuda.ipc_collect() save_sample_path = "" comment = f"Error. error information is {str(e)}" - return {"message": comment} + return {"message": comment, "save_sample_path": None, "base64_encoding": None} import torch.distributed as dist if dist.get_rank() == 0: if save_sample_path != "": return {"message": comment, "save_sample_path": save_sample_path, "base64_encoding": encode_file_to_base64(save_sample_path)} else: - return {"message": comment, "save_sample_path": save_sample_path} + return {"message": comment, "save_sample_path": save_sample_path, "base64_encoding": None} return None except Exception as e: - self.logger.error(f"Error generating image: {str(e)}") + print(f"Error generating image: {str(e)}") raise HTTPException(status_code=500, detail=str(e)) class MultiNodesEngine: