From cac9840c008a2cc0c331df09718ad15cb113d64c Mon Sep 17 00:00:00 2001 From: camenduru <54370274+camenduru@users.noreply.github.com> Date: Thu, 22 Aug 2024 02:02:26 +0300 Subject: [PATCH] test --- __init__.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..b9f3d11 --- /dev/null +++ b/__init__.py @@ -0,0 +1,43 @@ +import os + +import numpy as np +import requests +from PIL import Image + +import folder_paths + +class SendToTostAIWebhook: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "images": ("IMAGE",), + "webhook_url": ("STRING", {"default": "https://tost.ai/api/webhook/YOUR_WEBHOOK_KEY_HERE"}), + }, + } + + RETURN_TYPES = ("STRING",) + OUTPUT_NODE = True + CATEGORY = "TostAI" + FUNCTION = "send_to_tost_ai_webhook" + + def send_to_tost_ai_webhook(self, images, webhook_url: str,): + full_output_folder, filename = folder_paths.get_save_image_path("final_tost", folder_paths.get_temp_directory()) + tost_file_path = os.path.join(full_output_folder, f"{filename}_.png") + tost_image = 255.0 * images[0].cpu().numpy() + tost_image_pil = Image.fromarray(tost_image.astype(np.uint8)) + tost_image_pil.save(tost_file_path) + response = requests.post(webhook_url, files={"file": open(tost_file_path, "rb")}) + if response.status_code == 204: + print("Successfully uploaded file to TostAI.") + else: + print(f"Failed to upload file. Status code: {response.status_code}:{response.text}") + return (f"{response.status_code}:{response.text}"", ) + +NODE_CLASS_MAPPINGS = { + "SendToTostAIWebhook": SendToTostAIWebhook, +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "SendToTostAIWebhook": "Send To Tost AI Webhook", +} \ No newline at end of file