| 68 | |
| 69 | |
| 70 | def generate_metadata(self, folder): |
| 71 | image_list, prompt_list = [], [] |
| 72 | file_set = set(os.listdir(folder)) |
| 73 | for file_name in file_set: |
| 74 | if "." not in file_name: |
| 75 | continue |
| 76 | file_ext_name = file_name.split(".")[-1].lower() |
| 77 | file_base_name = file_name[:-len(file_ext_name)-1] |
| 78 | if file_ext_name not in self.image_file_extension: |
| 79 | continue |
| 80 | prompt_file_name = file_base_name + ".txt" |
| 81 | if prompt_file_name not in file_set: |
| 82 | continue |
| 83 | with open(os.path.join(folder, prompt_file_name), "r", encoding="utf-8") as f: |
| 84 | prompt = f.read().strip() |
| 85 | image_list.append(file_name) |
| 86 | prompt_list.append(prompt) |
| 87 | metadata = pd.DataFrame() |
| 88 | metadata["image"] = image_list |
| 89 | metadata["prompt"] = prompt_list |
| 90 | return metadata |
| 91 | |
| 92 | |
| 93 | def crop_and_resize(self, image, target_height, target_width): |