From faf7ed9a0753d619d228b1e992c5c0b2ba0ebca3 Mon Sep 17 00:00:00 2001 From: daxcay Date: Fri, 14 Jun 2024 19:10:45 +0530 Subject: [PATCH] Updates --- classes/DATASET_CaptionVisualizer.py | 6 +++--- classes/DATASET_OpenAIChatImage.py | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/classes/DATASET_CaptionVisualizer.py b/classes/DATASET_CaptionVisualizer.py index 8fa4d37..001e306 100644 --- a/classes/DATASET_CaptionVisualizer.py +++ b/classes/DATASET_CaptionVisualizer.py @@ -176,15 +176,15 @@ class DATASET_CaptionVisualizer: OUTPUT_NODE = True CATEGORY = "🔶DATASET🔶" - def Visualize(self, TextFilePathList, WordCloudTop, NetworkGraphTop, FrequencyGraphTop): + def Visualize(self, Captions, WordCloudTop, NetworkGraphTop, FrequencyGraphTop): try: - directory_path = os.path.dirname(TextFilePathList[0]) + directory_path = os.path.dirname(Captions[0]) visualize_path = os.path.join(directory_path, "visualize") os.makedirs(visualize_path, exist_ok=True) wc, ng, fg = generate_wordcloud_and_network_graph( - TextFilePathList, visualize_path, WordCloudTop[0], NetworkGraphTop[0], FrequencyGraphTop[0]) + Captions, visualize_path, WordCloudTop[0], NetworkGraphTop[0], FrequencyGraphTop[0]) images = [] if os.path.exists(wc): diff --git a/classes/DATASET_OpenAIChatImage.py b/classes/DATASET_OpenAIChatImage.py index 4cb17f4..09a08c0 100644 --- a/classes/DATASET_OpenAIChatImage.py +++ b/classes/DATASET_OpenAIChatImage.py @@ -37,16 +37,19 @@ class DATASET_OpenAIChatImage: def generate(self, image, image_detail, model, api_url, api_key, prompt, token_length): try: + ai = OpenAI(api_key=api_key, base_url=api_url) base64img = self.to_base64(image) if not api_key: return "OpenAI API key is required." - request = [{"role": "system","content": "You are GPT-4"}] - request.extend({"role": "user","content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{base64img}", "detail": image_detail}}]}) - request.extend({"role": "user","content": prompt}) + + request = [{"role": "system","content": "You are GPT-4."}] + request.append({"role": "user","content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{base64img}", "detail": image_detail}}]}) + request.append({"role": "user","content": prompt}) response = ai.chat.completions.create(model=model,messages=request,max_tokens=token_length) answer = response.choices[0].message.content return (answer,) + except Exception as e: return (f"Error: {str(e)}",)