LanguageBind commited on
Commit
6fbeeda
·
verified ·
1 Parent(s): c8da9c5

Upload check.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. check.py +52 -0
check.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from tqdm import tqdm
3
+ def check_text_fields(json_file_path):
4
+ """
5
+ 检查JSON文件中所有字典的text字段是否为空
6
+
7
+ Args:
8
+ json_file_path (str): JSON文件路径
9
+ """
10
+ try:
11
+ # 读取JSON文件
12
+ with open(json_file_path, 'r', encoding='utf-8') as f:
13
+ data = json.load(f)
14
+
15
+ # 检查是否为列表
16
+ if not isinstance(data, list):
17
+ raise ValueError("JSON文件应该包含一个列表")
18
+
19
+ # 检查每个字典的text字段
20
+ errors = []
21
+ for i, item in tqdm(enumerate(data)):
22
+ if not isinstance(item, dict):
23
+ errors.append(f"索引 {i}: 不是字典类型")
24
+ continue
25
+
26
+ print(len(item['text']))
27
+ if 'text' not in item:
28
+ errors.append(f"索引 {i}: 缺少text字段")
29
+ elif item['text'] is None or item['text'].strip() == '':
30
+ errors.append(f"索引 {i}: text字段为空")
31
+ else:
32
+ print(f"索引 {i}: text字段正常")
33
+
34
+ # 输出检查结果
35
+ if errors:
36
+ print(f"发现 {len(errors)} 个错误:")
37
+ for error in errors:
38
+ print(f" - {error}")
39
+ raise ValueError("存在空的text字段")
40
+ else:
41
+ print("所有text字段都正常")
42
+
43
+ except FileNotFoundError:
44
+ print(f"错误: 文件 {json_file_path} 不存在")
45
+ except json.JSONDecodeError:
46
+ print(f"错误: {json_file_path} 不是有效的JSON文件")
47
+ except Exception as e:
48
+ print(f"错误: {str(e)}")
49
+
50
+ # 使用示例
51
+ json_file_path = "/mnt/new_cpfs/zhubin/VideoX-Fun/datasets/TriData/step2_multi_style_data_2w.json" # 替换为你的JSON文件路径
52
+ check_text_fields(json_file_path)