zs_ai_post_ai_render_script.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from __future__ import (
  2. print_function,
  3. ) # Ensure print() function is available in Python 2
  4. import sys
  5. import json
  6. import requests
  7. import base64
  8. from Deadline.Scripting import * # Import Deadline script utilities
  9. api_path = "https://canvas-api-test.anvil.app/_/api"
  10. image_path = (
  11. "D:/Git/ap-canvas-creation-module/03_blender/sd_blender/sample_scene/Renders/"
  12. )
  13. # def update_3d_image_task_status(row_id, new_status):
  14. # # Define the URL for the API endpoint
  15. # url = "{}/tasks/3d-image/update-status".format(api_path)
  16. # # Create a JSON payload
  17. # payload = {"row_id": row_id, "new_status": new_status}
  18. # # Make a POST request to the API endpoint with the JSON payload
  19. # response = requests.post(url, json=payload)
  20. # # Handle the response
  21. # if response.status_code == 200:
  22. # print("Status update was successful")
  23. # return response.json()
  24. # else:
  25. # print("Status update failed")
  26. # print("Status code:", response.status_code)
  27. # print("Response:", response.text)
  28. # return None
  29. # def get_3d_image_task(row_id):
  30. # # Define the URL for the API endpoint
  31. # url = "{}/tasks/3d-image/{}".format(api_path, row_id)
  32. # print("Constructed URL:", url) # Print the URL for debugging
  33. # # Make a GET request to the API endpoint
  34. # response = requests.get(url)
  35. # # Handle the response
  36. # if response.status_code == 200:
  37. # print("Request was successful")
  38. # return response.json()
  39. # else:
  40. # print("Request failed")
  41. # print("Status code:", response.status_code)
  42. # print("Response:", response.text)
  43. # return None
  44. # def find_image_and_convert_to_base64(image_path):
  45. # with open(image_path, "rb") as image_file:
  46. # image_data = image_file.read()
  47. # image_base64 = base64.b64encode(image_data).decode("utf-8")
  48. # return image_base64
  49. # def upload_image_to_anvil(row_id, image_base64):
  50. # url = "{}/test-2".format(api_path)
  51. # payload = {"row_id": row_id, "image_base64": image_base64}
  52. # response = requests.post(url, json=payload)
  53. # if response.status_code == 200:
  54. # print("Image uploaded successfully")
  55. # update_3d_image_task_status(row_id=row_id, new_status=3)
  56. # return response.json()
  57. # else:
  58. # print("Image upload failed")
  59. # print("Status code:", response.status_code)
  60. # print("Response:", response.text)
  61. # return None
  62. def __main__(*args):
  63. deadlinePlugin = args[0]
  64. job = deadlinePlugin.GetJob()
  65. print("AI image completed")
  66. # row_id = job.JobExtraInfo0
  67. # response = get_3d_image_task(row_id)
  68. # data = json.loads(response["data"])
  69. # project_id = data["project_id"]
  70. # image_base64 = find_image_and_convert_to_base64(
  71. # image_path + "{}/base0001.jpg".format(project_id)
  72. # )
  73. # upload_image_to_anvil(row_id, image_base64)
  74. if __name__ == "__main__":
  75. __main__(sys.argv)