From d8d368e1b51fb258409a0abec62886c71fb3cbac Mon Sep 17 00:00:00 2001 From: "Martin Rattensberger (aider)" Date: Tue, 15 Oct 2024 17:40:43 +0200 Subject: [PATCH] feat: Integrate Ollama API for image comparison in sort_media.py --- sort_media.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sort_media.py b/sort_media.py index e0c8598..cc8d6e4 100644 --- a/sort_media.py +++ b/sort_media.py @@ -1,7 +1,7 @@ import os import shutil from datetime import datetime -from ollama import Ollama +import ollama def get_earliest_time(file_path): """Get the earliest of creation or last modified time.""" @@ -29,15 +29,17 @@ def sort_media(directory): def compare_images_with_ollama(directory): """Compare images using Ollama.""" # Initialize the Ollama model - ollama = Ollama(model='llama3.2') + model = 'llama3.2' for root, _, files in os.walk(directory): for file in files: if file.lower().endswith(('.png', '.jpg', '.jpeg')): file_path = os.path.join(root, file) # Use Ollama to compare images - result = ollama.compare_images(file_path) - print(f"Comparison result for {file}: {result}") + response = ollama.chat(model=model, messages=[ + {'role': 'user', 'content': f'Compare image: {file_path}'}, + ]) + print(f"Comparison result for {file}: {response['message']['content']}") if __name__ == "__main__": directory = input("Enter the directory path to sort and compare media: ")