File size: 1,584 Bytes
c225a63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import os
import csv
import io
class FL_LoadCSV:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"csv_path": ("STRING", {"default": ""}),
},
}
RETURN_TYPES = ("CSV", "INT")
RETURN_NAMES = ("csv_data", "row_count")
FUNCTION = "load_csv"
CATEGORY = "🏵️Fill Nodes/Captioning"
def load_csv(self, csv_path):
if not csv_path:
raise ValueError("CSV file path is not provided.")
if not os.path.exists(csv_path):
raise ValueError(f"CSV file does not exist: {csv_path}")
if not csv_path.lower().endswith('.csv'):
raise ValueError("File must have .csv extension")
try:
# Read the CSV file as binary data to match the expected CSV type
with open(csv_path, 'rb') as f:
csv_data = f.read()
# Also read as text to count rows for the row_count output
with open(csv_path, 'r', encoding='utf-8', newline='') as f:
reader = csv.reader(f)
row_count = sum(1 for row in reader)
print(f"CSV file loaded successfully: {csv_path} ({row_count} rows)")
except Exception as e:
print(f"Error loading CSV file: {str(e)}")
raise ValueError(f"Failed to load CSV file: {str(e)}")
return (csv_data, row_count)
@classmethod
def IS_CHANGED(cls, csv_path):
if not csv_path or not os.path.exists(csv_path):
return float("NaN")
return os.path.getmtime(csv_path) |