Fix bug in api (#192)

* Fix bug in api

* Fix bug in api
This commit is contained in:
Bubbliiiing
2025-04-30 10:55:17 +08:00
committed by GitHub
parent b0fe858bd6
commit cc609b4d87
11 changed files with 29 additions and 12 deletions
+2
View File
@@ -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')
@@ -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
+2
View File
@@ -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
+2
View File
@@ -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
+4 -3
View File
@@ -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()
+2
View File
@@ -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')
+2
View File
@@ -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
+4 -2
View File
@@ -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
@@ -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
+2 -2
View File
@@ -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}
return {"message": comment, "save_sample_path": save_sample_path, "base64_encoding": None}
+3 -3
View File
@@ -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: