| 206 | |
| 207 | |
| 208 | def generate_metadata(self, folder): |
| 209 | video_list, prompt_list = [], [] |
| 210 | file_set = set(os.listdir(folder)) |
| 211 | for file_name in file_set: |
| 212 | if "." not in file_name: |
| 213 | continue |
| 214 | file_ext_name = file_name.split(".")[-1].lower() |
| 215 | file_base_name = file_name[:-len(file_ext_name)-1] |
| 216 | if file_ext_name not in self.image_file_extension and file_ext_name not in self.video_file_extension: |
| 217 | continue |
| 218 | prompt_file_name = file_base_name + ".txt" |
| 219 | if prompt_file_name not in file_set: |
| 220 | continue |
| 221 | with open(os.path.join(folder, prompt_file_name), "r", encoding="utf-8") as f: |
| 222 | prompt = f.read().strip() |
| 223 | video_list.append(file_name) |
| 224 | prompt_list.append(prompt) |
| 225 | metadata = pd.DataFrame() |
| 226 | metadata["video"] = video_list |
| 227 | metadata["prompt"] = prompt_list |
| 228 | return metadata |
| 229 | |
| 230 | |
| 231 | def crop_and_resize(self, image, target_height, target_width): |