File size: 1,821 Bytes
9830017
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

def export_files_to_txt(file_list, output_file):
    # Các đuôi file văn bản phổ biến
    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:
            # Kiểm tra file có tồn tại không
            if not os.path.exists(file_path):
                outfile.write(f"[LỖI] File không tồn tại: {file_path}\n\n")
                continue

            # Kiểm tra định dạng file
            _, 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}")

# --- Cấu hình danh sách file ở đây ---
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)