working async
This commit is contained in:
committed by
Michael Wagner
parent
f01b8af1d3
commit
4e5f483492
@@ -164,21 +164,33 @@ async def status(uid: str):
|
|||||||
Returns:
|
Returns:
|
||||||
StatusResponse: Current status of the task and result if completed
|
StatusResponse: Current status of the task and result if completed
|
||||||
"""
|
"""
|
||||||
save_file_path = os.path.join(SAVE_DIR, f'{uid}.glb')
|
# Check for textured file first (preferred output)
|
||||||
print(save_file_path, os.path.exists(save_file_path))
|
textured_file_path = os.path.join(SAVE_DIR, f'{uid}_textured.glb')
|
||||||
if not os.path.exists(save_file_path):
|
initial_file_path = os.path.join(SAVE_DIR, f'{uid}_initial.glb')
|
||||||
response = {'status': 'processing'}
|
|
||||||
return JSONResponse(response, status_code=200)
|
print(f"Checking files: {textured_file_path} ({os.path.exists(textured_file_path)}), {initial_file_path} ({os.path.exists(initial_file_path)})")
|
||||||
else:
|
|
||||||
|
# If textured file exists, generation is complete
|
||||||
|
if os.path.exists(textured_file_path):
|
||||||
try:
|
try:
|
||||||
base64_str = base64.b64encode(open(save_file_path, 'rb').read()).decode()
|
base64_str = base64.b64encode(open(textured_file_path, 'rb').read()).decode()
|
||||||
response = {'status': 'completed', 'model_base64': base64_str}
|
response = {'status': 'completed', 'model_base64': base64_str}
|
||||||
return JSONResponse(response, status_code=200)
|
return JSONResponse(response, status_code=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error reading file {save_file_path}: {e}")
|
logger.error(f"Error reading file {textured_file_path}: {e}")
|
||||||
response = {'status': 'error', 'message': 'Failed to read generated file'}
|
response = {'status': 'error', 'message': 'Failed to read generated file'}
|
||||||
return JSONResponse(response, status_code=500)
|
return JSONResponse(response, status_code=500)
|
||||||
|
|
||||||
|
# If only initial file exists, texturing is in progress
|
||||||
|
elif os.path.exists(initial_file_path):
|
||||||
|
response = {'status': 'texturing'}
|
||||||
|
return JSONResponse(response, status_code=200)
|
||||||
|
|
||||||
|
# If no files exist, still processing
|
||||||
|
else:
|
||||||
|
response = {'status': 'processing'}
|
||||||
|
return JSONResponse(response, status_code=200)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|||||||
Reference in New Issue
Block a user