Stage I: Presentation Analysis. This stage is to analyze the presentation: cluster slides into different layouts, and extract content schema for each layout.
| 12 | |
| 13 | |
| 14 | class SlideInducter: |
| 15 | """ |
| 16 | Stage I: Presentation Analysis. |
| 17 | This stage is to analyze the presentation: cluster slides into different layouts, and extract content schema for each layout. |
| 18 | """ |
| 19 | |
| 20 | def __init__( |
| 21 | self, |
| 22 | prs: Presentation, |
| 23 | ppt_image_folder: str, |
| 24 | template_image_folder: str, |
| 25 | config: Config, |
| 26 | image_models: list, |
| 27 | ): |
| 28 | """ |
| 29 | Initialize the SlideInducter. |
| 30 | |
| 31 | Args: |
| 32 | prs (Presentation): The presentation object. |
| 33 | ppt_image_folder (str): The folder containing PPT images. |
| 34 | template_image_folder (str): The folder containing normalized slide images. |
| 35 | config (Config): The configuration object. |
| 36 | image_models (list): A list of image models. |
| 37 | """ |
| 38 | self.prs = prs |
| 39 | self.config = config |
| 40 | self.ppt_image_folder = ppt_image_folder |
| 41 | self.template_image_folder = template_image_folder |
| 42 | assert ( |
| 43 | len(os.listdir(template_image_folder)) |
| 44 | == len(prs) |
| 45 | == len(os.listdir(ppt_image_folder)) |
| 46 | ) |
| 47 | self.image_models = image_models |
| 48 | self.slide_induction = defaultdict(lambda: defaultdict(list)) |
| 49 | model_identifier = llms.get_simple_modelname( |
| 50 | [llms.language_model, llms.vision_model] |
| 51 | ) |
| 52 | self.output_dir = pjoin(config.RUN_DIR, "template_induct", model_identifier) |
| 53 | self.split_cache = pjoin(self.output_dir, f"split_cache.json") |
| 54 | self.induct_cache = pjoin(self.output_dir, f"induct_cache.json") |
| 55 | os.makedirs(self.output_dir, exist_ok=True) |
| 56 | |
| 57 | def layout_induct(self): |
| 58 | """ |
| 59 | Perform layout induction for the presentation. |
| 60 | """ |
| 61 | if pexists(self.induct_cache): |
| 62 | return json.load(open(self.induct_cache)) |
| 63 | content_slides_index, functional_cluster = self.category_split() |
| 64 | for layout_name, cluster in functional_cluster.items(): |
| 65 | for slide_idx in cluster: |
| 66 | content_type = self.prs.slides[slide_idx - 1].get_content_type() |
| 67 | self.slide_induction[layout_name + ":" + content_type]["slides"].append( |
| 68 | slide_idx |
| 69 | ) |
| 70 | for layout_name, cluster in self.slide_induction.items(): |
| 71 | cluster["template_id"] = cluster["slides"][-1] |