| import os |
|
|
| def export_files_to_txt(file_list, output_file): |
| |
| text_extensions = {'.py', '.txt', '.md', '.json', '.yaml', '.yml', '.c', '.cpp', '.h', '.sql', '.html', '.css', '.js'} |
|
|
| with open(output_file, 'w', encoding='utf-8') as outfile: |
| for file_path in file_list: |
| |
| if not os.path.exists(file_path): |
| outfile.write(f"[LỖI] File không tồn tại: {file_path}\n\n") |
| continue |
|
|
| |
| _, ext = os.path.splitext(file_path) |
| if ext.lower() in text_extensions: |
| try: |
| with open(file_path, 'r', encoding='utf-8') as infile: |
| content = infile.read() |
| |
| outfile.write(f"{'='*80}\n") |
| outfile.write(f"FILE PATH: {file_path}\n") |
| outfile.write(f"{'='*80}\n\n") |
| outfile.write(content) |
| outfile.write("\n\n") |
| |
| except Exception as e: |
| outfile.write(f"[LỖI] Không thể đọc file {file_path}: {e}\n\n") |
| else: |
| outfile.write(f"[BỎ QUA] Định dạng file không hỗ trợ: {file_path}\n\n") |
|
|
| print(f"Xong! Nội dung đã được lưu vào: {output_file}") |
|
|
| |
| files_to_export = [ |
| '/kaggle/embedding-inversion-demo/dataset.py', |
| '/kaggle/embedding-inversion-demo/configs/v2_qwen3.yaml', |
| '/kaggle/embedding-inversion-demo/model.py', |
| '/kaggle/embedding-inversion-demo/train.py' |
| ] |
|
|
| file_out = '/kaggle/embedding-inversion-demo/prompt.txt' |
| export_files_to_txt(files_to_export, file_out) |