Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import os | |
| def convert_csv_to_txt(input_csv: str = "documents/supabase_docs.csv", output_folder: str = "documents"): | |
| """Converte ogni riga del CSV in un file .txt nella cartella documents/""" | |
| if not os.path.exists(input_csv): | |
| print(f"CSV non trovato: {input_csv}") | |
| return | |
| df = pd.read_csv(input_csv) | |
| for idx, row in df.iterrows(): | |
| content = row.get("content") or row.get("page_content") or "" | |
| if not isinstance(content, str) or not content.strip(): | |
| continue | |
| filename = os.path.join(output_folder, f"doc_{idx+1}.txt") | |
| with open(filename, "w", encoding="utf-8") as f: | |
| f.write(content.strip()) | |
| print(f"CSV convertito: {len(df)} righe elaborate.") | |
| convert_csv_to_txt() |