From 0a6e57b7daadc208c6a11e9b652261c877cc5297 Mon Sep 17 00:00:00 2001 From: pliny <133052465+elder-plinius@users.noreply.github.com> Date: Wed, 5 Mar 2025 14:58:31 -0500 Subject: [PATCH] Delete openai_vision.py --- openai_vision.py | 50 ------------------------------------------------ 1 file changed, 50 deletions(-) delete mode 100644 openai_vision.py diff --git a/openai_vision.py b/openai_vision.py deleted file mode 100644 index 811c073..0000000 --- a/openai_vision.py +++ /dev/null @@ -1,50 +0,0 @@ -import base64 -import openai -import os - -class OpenAIVision: - def __init__(self): - # Ensure your OpenAI API key is set in the environment variables - self.api_key = os.getenv("OPENAI_API_KEY") - if not self.api_key: - raise ValueError("The OPENAI_API_KEY environment variable has not been set.") - openai.api_key = self.api_key - - @staticmethod - def encode_image_to_base64(image_path): - with open(image_path, "rb") as image_file: - return base64.b64encode(image_file.read()).decode('utf-8') - - def analyze_image(self, image_path): - """ - Analyze an image and return the model's description or analysis. - - :param image_path: Path to the image file - :return: Description or analysis of the image - """ - base64_image = self.encode_image_to_base64(image_path) - - try: - response = openai.chat.completions.create( - model="gpt-4-vision-preview", - messages=[ - { - "role": "user", - "content": [ - {"type": "text", "text": "Analyze this image"}, - {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}} - ] - } - ], - max_tokens=3000 - ) - return response.choices[0].message.content - except Exception as e: - print(f"An error occurred: {e}") - return None - -if __name__ == "__main__": - vision_model = OpenAIVision() - image_path = "image0.jpeg" # Replace with the path to your image - description = vision_model.analyze_image(image_path) - print(description)