import sys import os from rembg import remove from PIL import Image def process_file(file_path): print(f"Processing: {file_path}") try: if not os.path.exists(file_path): print(f"Error: File {file_path} not found.") return with open(file_path, "rb") as input_file: input_data = input_file.read() output_data = remove(input_data) # Save as png (force extension if needed) output_path = os.path.splitext(file_path)[0] + ".png" with open(output_path, "wb") as output_file: output_file.write(output_data) print(f"Success! Saved to {output_path}") except ImportError: print("Error: Required libraries (rembg, PIL) not found. Please install them.") except Exception as e: print(f"Error processing file: {e}") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python single_rembg.py ") else: process_file(sys.argv[1])