feat: Integrate Ollama API for image comparison in sort_media.py
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from ollama import Ollama
|
import ollama
|
||||||
|
|
||||||
def get_earliest_time(file_path):
|
def get_earliest_time(file_path):
|
||||||
"""Get the earliest of creation or last modified time."""
|
"""Get the earliest of creation or last modified time."""
|
||||||
@@ -29,15 +29,17 @@ def sort_media(directory):
|
|||||||
def compare_images_with_ollama(directory):
|
def compare_images_with_ollama(directory):
|
||||||
"""Compare images using Ollama."""
|
"""Compare images using Ollama."""
|
||||||
# Initialize the Ollama model
|
# Initialize the Ollama model
|
||||||
ollama = Ollama(model='llama3.2')
|
model = 'llama3.2'
|
||||||
|
|
||||||
for root, _, files in os.walk(directory):
|
for root, _, files in os.walk(directory):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
||||||
file_path = os.path.join(root, file)
|
file_path = os.path.join(root, file)
|
||||||
# Use Ollama to compare images
|
# Use Ollama to compare images
|
||||||
result = ollama.compare_images(file_path)
|
response = ollama.chat(model=model, messages=[
|
||||||
print(f"Comparison result for {file}: {result}")
|
{'role': 'user', 'content': f'Compare image: {file_path}'},
|
||||||
|
])
|
||||||
|
print(f"Comparison result for {file}: {response['message']['content']}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
directory = input("Enter the directory path to sort and compare media: ")
|
directory = input("Enter the directory path to sort and compare media: ")
|
||||||
|
|||||||
Reference in New Issue
Block a user