essbase using max_threads import import os import re from tkinter import Tk, Label, StringVar from tkinterdnd2 import DND_FILES, TkinterDnD from PIL import Image from tesserocr import PyTessBaseAPI from concurrent.futures import ThreadPoolExecutor MAX_THREADS = 2 # multi-threading def rename_based_on_ocr(filepath): essbase using max_threads import How to get it for free? essbase using max_threads import if filepath.endswith((".jpg", ".jfif", ".png", ".gif")): try: with Image.open(filepath) as img: # Use tesserocr to OCR the image with PyTessBaseAPI() as api: api.SetImage(img) text = api.GetUTF8Text().strip() # Excluding certain OCR words exclude_words = ["Replying to", "top comments", "sorted by", "From Wikipedia the free encyclopedia", "likes", "jpg", "png", "KB", "No", "yes", "ANONYMOUS", "Anymous", "ID", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "ID", "File", "Reply", "Subscribe", "SUBSCRIBE","Now", "NOW", "Login", "LOGIN", "FOLLOWING", "FOLLOWERS", "You Retweeted", "Follow", "http", "www", "com", "https", "Translator", "iadb", "GMT", "httpiwww", "httpwww", "Google Translate", "---", "--", "----", "-", "Share this article", "hours ago", "View replies", "Twitter for iPhone", "google yandex igdb wait"] essbase using max_threads import How to get it for free? essbase using max_threads import for word in exclude_words: text = text.replace(word, '') # Remove 2-letter words text = ' '.join([word for word in text.split() if len(word) > 2]) # Remove all numbers longer than 4 digits modified_text = [] for word in text.split(): if not word.isdigit() or (word.isdigit() and len(word) <= 4): essbase using max_threads import How to get it for free? essbase using max_threads import modified_text.append(word) text = ' '.join(modified_text) # Use only the first 100 characters and replace invalid filename characters new_name = ''.join(e for e in text[:120] if e.isalnum() or e in [' ', '-']).rstrip().replace(" ", " ") + os.path.splitext(filepath)[-1] # If no valid characters are found or new_name becomes empty, retain the original name if not new_name.strip() or new_name == os.path.splitext(filepath)[-1]: return f"File {os.path.basename(filepath)} remains unchanged." essbase using max_threads import How to get it? essbase using max_threads import # Avoid overwriting files new_filepath = os.path.join(os.path.dirname(filepath), new_name) count = 1 while os.path.exists(new_filepath) and new_filepath != filepath: new_name_base, ext = os.path.splitext(new_name) new_filepath = os.path.join(os.path.dirname(filepath), f"{new_name_base}_{count}{ext}") count += 1 # Rename the file os.rename(filepath, new_filepath) essbase using max_threads import How to use it? essbase using max_threads import except Exception as e: return f"Error processing file {os.path.basename(filepath)}: {e}" return f"Successfully renamed {os.path.basename(filepath)}" def on_drop(event): files = root.tk.splitlist(event.data) with ThreadPoolExecutor(max_workers=MAX_THREADS) as executor: results = list(executor.map(rename_based_on_ocr, files)) essbase using max_threads import How to dowload it? essbase using max_threads import # Update the status label with a summary errors = [r for r in results if "Error" in r] status_var.set(f"Processed {len(files)} files. Errors: {len(errors)}") root = TkinterDnD.Tk() root.title("Drag & Drop OCR Renamer") Label(root, text="Drag & drop your image files here").pack(pady=20) status_var = StringVar() essbase using max_threads import How to use it? essbase using max_threads import status_label = Label(root, textvariable=status_var) status_label.pack(pady=10) root.drop_target_register(DND_FILES) root.dnd_bind('<>', on_drop) root.mainloop() essbase using max_threads import