10/18/2024
Ollama (https://ollama.com/)
You can run Meta's LLM (Llama3.2:1b) locally (no calls to remote API's) on a regular laptop (no GPU required) and use it to write code. The following program was created by this approach:
import os
from PIL import Image
import sys
import os
def create_directory(directory_name,write_directory="saved"):
"""
Creates a directory with the given name if it does not exist.
Args:
directory_name (str): The name of the directory to be created.
"""
# Check if the directory exists
if not os.path.exists(directory_name):
try:
# Create the directory and all its parents if they do not exist
os.makedirs(os.path.dirname(directory_name), exist_ok=True)
print(f"Created '{directory_name}'")
except OSError as e:
print(f"Failed to create '{directory_name}': {e}")
def resize_images(read_directory, write_directory):
"""
Resizes images in a given directory to 640x480 pixels.
Args:
directory (str): The path to the directory containing images.
"""
create_directory(write_directory)
# Check if the directory exists
if not os.path.exists(read_directory):
print(f"Directory '{read_directory}' does not exist.")
return
# Iterate over all files in the directory
for filename in os.listdir(read_directory):
# Construct the full file path
filepath = os.path.join(read_directory, filename)
# Check if it's an image file
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp','.tiff','.tif')):
try:
# Open and resize the image
img = Image.open(filepath)
width, height = 640*2, 480*2
img = img.resize((width, height))
# Save the resized image as a PNG file
new_filename = f"{filename[:-4]}.png"
img.save(os.path.join(write_directory, new_filename))
print(f"Resized {filename} to 640x480 pixels and saved as {new_filename}")
except Exception as e:
print(f"Failed to resize {filename}: {e}")
if __name__ == "__main__":
# Example usage
read_directory = sys.argv[1]
write_directory = sys.argv[2]
resize_images(read_directory, write_directory)