From dc48b7d21e571edc9bcbf67b826404516336dd9b Mon Sep 17 00:00:00 2001 From: Alexis LEBEL Date: Sun, 2 Apr 2023 14:42:37 +0200 Subject: [PATCH] [Images] Fixed images recognition with google --- code/makeprompt.py | 8 ++++---- code/vision_processing.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/code/makeprompt.py b/code/makeprompt.py index a24215a..890af34 100644 --- a/code/makeprompt.py +++ b/code/makeprompt.py @@ -398,16 +398,16 @@ async def gpt_prompt(bot, messages, message, data_dict, prompt, guild_data): ): for attachment in msg.attachments: path = f"./../database/google-vision/results/{attachment.id}.txt" - if images_usage >= 6 and guild_data["premium"] == 0: + if data_dict['images_usage'] >= 6 and guild_data["premium"] == 0: guild_data["images_limit_reached"] = True - elif images_usage >= 30 and guild_data["premium"] == 1: + elif data_dict['images_usage'] >= 30 and guild_data["premium"] == 1: guild_data["images_limit_reached"] = True if ( attachment.url.endswith((".png", ".jpg", ".jpeg", ".gif")) and not guild_data["images_limit_reached"] and not os.path.exists(path) ): - images_usage += 1 + data_dict['images_usage'] += 1 analysis = await vision_processing.process(attachment) if analysis != None: content = f"{content} \n\n {analysis}" @@ -446,7 +446,7 @@ async def gpt_prompt(bot, messages, message, data_dict, prompt, guild_data): ) curs_data.execute( "UPDATE images SET usage_count = ? WHERE guild_id = ?", - (images_usage, message.guild.id), + (data_dict['images_usage'], message.guild.id), ) else: msgs.append({"role": role, "content": f"{content}", "name": name}) diff --git a/code/vision_processing.py b/code/vision_processing.py index 8f0fcf0..85d610a 100644 --- a/code/vision_processing.py +++ b/code/vision_processing.py @@ -10,7 +10,7 @@ from google.cloud import vision try: client = vision.ImageAnnotatorClient() except: - debug("Google Vision API is not setup, please run /setup") + print("Google Vision API is not setup, please run /setup") @@ -64,4 +64,4 @@ async def process(attachment): return final except Exception as e: - debug("Error while processing image: " + str(e)) + print("Error while processing image: " + str(e))