StyleVideoDataSet / check.py
LanguageBind's picture
Upload check.py with huggingface_hub
6fbeeda verified
Raw History Blame
1.84 kB
import json
from tqdm import tqdm
def check_text_fields(json_file_path):
"""
检查JSON文件中所有字典的text字段是否为空
Args:
json_file_path (str): JSON文件路径
"""
try:
# 读取JSON文件
with open(json_file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# 检查是否为列表
if not isinstance(data, list):
raise ValueError("JSON文件应该包含一个列表")
# 检查每个字典的text字段
errors = []
for i, item in tqdm(enumerate(data)):
if not isinstance(item, dict):
errors.append(f"索引 {i}: 不是字典类型")
continue
print(len(item['text']))
if 'text' not in item:
errors.append(f"索引 {i}: 缺少text字段")
elif item['text'] is None or item['text'].strip() == '':
errors.append(f"索引 {i}: text字段为空")
else:
print(f"索引 {i}: text字段正常")
# 输出检查结果
if errors:
print(f"发现 {len(errors)} 个错误:")
for error in errors:
print(f" - {error}")
raise ValueError("存在空的text字段")
else:
print("所有text字段都正常")
except FileNotFoundError:
print(f"错误: 文件 {json_file_path} 不存在")
except json.JSONDecodeError:
print(f"错误: {json_file_path} 不是有效的JSON文件")
except Exception as e:
print(f"错误: {str(e)}")
# 使用示例
json_file_path = "/mnt/new_cpfs/zhubin/VideoX-Fun/datasets/TriData/step2_multi_style_data_2w.json" # 替换为你的JSON文件路径
check_text_fields(json_file_path)