MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / layout_induct

Method layout_induct

utils/src/induct.py:57–98  ·  view source on GitHub ↗

Perform layout induction for the presentation.

(self)

Source from the content-addressed store, hash-verified

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]
72
73 functional_keys = list(self.slide_induction.keys())
74 function_slides_index = set()
75 for layout_name, cluster in self.slide_induction.items():
76 function_slides_index.update(cluster["slides"])
77 used_slides_index = function_slides_index.union(content_slides_index)
78 for i in range(len(self.prs.slides)):
79 if i + 1 not in used_slides_index:
80 content_slides_index.add(i + 1)
81 self.layout_split(content_slides_index)
82 if self.config.DEBUG:
83 for layout_name, cluster in self.slide_induction.items():
84 cluster_dir = pjoin(self.output_dir, "cluster_slides", layout_name)
85 os.makedirs(cluster_dir, exist_ok=True)
86 for slide_idx in cluster["slides"]:
87 shutil.copy(
88 pjoin(self.ppt_image_folder, f"slide_{slide_idx:04d}.jpg"),
89 pjoin(cluster_dir, f"slide_{slide_idx:04d}.jpg"),
90 )
91 self.slide_induction["functional_keys"] = functional_keys
92 json.dump(
93 self.slide_induction,
94 open(self.induct_cache, "w"),
95 indent=4,
96 ensure_ascii=False,
97 )
98 return self.slide_induction
99
100 def category_split(self):
101 """

Callers 1

content_inductMethod · 0.95

Calls 7

category_splitMethod · 0.95
layout_splitMethod · 0.95
loadMethod · 0.45
get_content_typeMethod · 0.45
unionMethod · 0.45
addMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected