From 291003ecb829c14f562aa6fd38a6bdae1964ae15 Mon Sep 17 00:00:00 2001 From: Yolan Date: Sat, 30 Sep 2023 18:37:33 -0700 Subject: [PATCH] Add imagechat.py --- .gitignore | 1 + imagechat.py | 53 ++++++++++++++++++++++++++++++++++++++ imagechatconfig.py.example | 1 + 3 files changed, 55 insertions(+) create mode 100644 imagechat.py create mode 100644 imagechatconfig.py.example diff --git a/.gitignore b/.gitignore index 68bc17f..57a4938 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +imagechatconfig.py diff --git a/imagechat.py b/imagechat.py new file mode 100644 index 0000000..985ab76 --- /dev/null +++ b/imagechat.py @@ -0,0 +1,53 @@ +# Inference an Image on ImageChat-2, Image File Url +import requests +import json +from io import BytesIO + +from custom_nodes.DTAIImageToTextNode import imagechatconfig + + +def predict_api(model_id, image_file_url, api_key=None, parameters=None): + + payload = { + "image_file_url": image_file_url, + "model_id": model_id, + "parameters": parameters, + } + + url = "https://apiv2.chooch.ai/predict?api_key={}".format(api_key) + response = requests.put(url, data=json.dumps(payload)) + json_data = json.loads(response.content) + return json_data + + +# Chooch ImageChat-2 model_id +model_id_image_chat_pt = "ad420c2a-d565-48eb-b963-a8297a0e4000" +image_file_url = "" + +parameters = {} + +# Default is True. If a prompt is given only 1 class will be returned and deep_detection will be turned off +parameters["deep_inference"] = True +#parameters["prompt"] = ["describe in detail what is in the image", "describe the lighting in the image", "describe the camera work of the image"] + +parameters["workflow_predict_objects_only"] = False + +parameters["workflow_padding"] = 0.6 + +parameters["workflow_conf_thresh"] = 0.3 +parameters["workflow_nms_thresh"] = 0.45 + + +def image_url_to_text(url): + return predict_api( + model_id_image_chat_pt, url, api_key=imagechatconfig.apikey, parameters=parameters + ) + + +# main +if __name__ == "__main__": + print( + image_url_to_text( + "https://doubtech-aiart.s3.amazonaws.com/images/83cf4e5b-5147-4f9d-bf50-3fa4bca05b81.png" + ) + ) \ No newline at end of file diff --git a/imagechatconfig.py.example b/imagechatconfig.py.example new file mode 100644 index 0000000..a9a8517 --- /dev/null +++ b/imagechatconfig.py.example @@ -0,0 +1 @@ +apikey=""