svjack commited on
Commit
66689bb
·
verified ·
1 Parent(s): 874c5fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py CHANGED
@@ -33,6 +33,65 @@ for index, row in df.iterrows():
33
  continue
34
 
35
  print("所有行处理完成")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  '''
37
 
38
  import spaces
 
33
  continue
34
 
35
  print("所有行处理完成")
36
+
37
+
38
+ import pandas as pd
39
+ import pathlib
40
+ import numpy as np
41
+ import shutil
42
+ import os
43
+
44
+ # 获取HunyuanVideo-Foley目录下的MP4文件路径
45
+ l0 = pd.Series(list(pathlib.Path(".").rglob("*.mp4"))).map(str).map(
46
+ lambda x: x if "17563" in x else np.nan
47
+ ).dropna().sort_values().values.tolist()
48
+
49
+ # 读取CSV文件
50
+ df = pd.read_csv("wan_gen_videos_captioned/metadata.csv")
51
+ print(df.shape, len(l0))
52
+ df["file_name"] = pd.Series(l0).map(lambda x: x.split("/")[-1]).values.tolist()
53
+
54
+ # 创建目标文件夹
55
+ target_folder = "wan_gen_videos_HunyuanVideo_Foley_sound_captioned"
56
+ os.makedirs(target_folder, exist_ok=True)
57
+
58
+ # 处理每一行数据
59
+ for index, row in df.iterrows():
60
+ try:
61
+ # 获取源文件路径和目标文件路径
62
+ source_file = None
63
+ for file_path in l0:
64
+ if row['file_name'] in file_path:
65
+ source_file = file_path
66
+ break
67
+
68
+ if source_file:
69
+ # 复制MP4文件
70
+ target_mp4 = os.path.join(target_folder, row['file_name'])
71
+ shutil.copy2(source_file, target_mp4)
72
+
73
+ # 创建对应的文本文件
74
+ txt_filename = os.path.splitext(row['file_name'])[0] + '.txt'
75
+ txt_filepath = os.path.join(target_folder, txt_filename)
76
+
77
+ with open(txt_filepath, 'w', encoding='utf-8') as f:
78
+ f.write(row['prompt'])
79
+
80
+ print(f"成功处理: {row['file_name']} -> {txt_filename}")
81
+ else:
82
+ print(f"警告: 未找到文件 {row['file_name']}")
83
+
84
+ except Exception as e:
85
+ print(f"处理失败 - 行 {index}: {str(e)}")
86
+ continue
87
+
88
+ print("所有文件处理完成!")
89
+ print(f"文件已保存到: {target_folder}")
90
+
91
+ df.to_csv("wan_gen_videos_HunyuanVideo_Foley_sound_captioned/metadata.csv", index = False)
92
+
93
+ !cp README.md wan_gen_videos_HunyuanVideo_Foley_sound_captioned
94
+ !huggingface-cli upload svjack/wan_gen_videos_HunyuanVideo_Foley_sound_captioned wan_gen_videos_HunyuanVideo_Foley_sound_captioned --repo-type dataset
95
  '''
96
 
97
  import spaces