zs_ai_post_ai_render_script.py 2.8 KB

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