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

Method layout_split

utils/src/induct.py:126–162  ·  view source on GitHub ↗

Cluster slides into different layouts.

(self, content_slides_index: set[int])

Source from the content-addressed store, hash-verified

124 return content_slides_index, functional_cluster
125
126 def layout_split(self, content_slides_index: set[int]):
127 """
128 Cluster slides into different layouts.
129 """
130 embeddings = get_image_embedding(self.template_image_folder, *self.image_models)
131 assert len(embeddings) == len(self.prs)
132 template = Template(open("prompts/ask_category.txt").read())
133 content_split = defaultdict(list)
134 for slide_idx in content_slides_index:
135 slide = self.prs.slides[slide_idx - 1]
136 content_type = slide.get_content_type()
137 layout_name = slide.slide_layout_name
138 content_split[(layout_name, content_type)].append(slide_idx)
139
140 for (layout_name, content_type), slides in content_split.items():
141 sub_embeddings = [
142 embeddings[f"slide_{slide_idx:04d}.jpg"] for slide_idx in slides
143 ]
144 similarity = images_cosine_similarity(sub_embeddings)
145 for cluster in get_cluster(similarity):
146 slide_indexs = [slides[i] for i in cluster]
147 template_id = max(
148 slide_indexs,
149 key=lambda x: len(self.prs.slides[x - 1].shapes),
150 )
151 cluster_name = (
152 llms.vision_model(
153 template.render(
154 existed_layoutnames=list(self.slide_induction.keys()),
155 ),
156 pjoin(self.ppt_image_folder, f"slide_{template_id:04d}.jpg"),
157 )
158 + ":"
159 + content_type
160 )
161 self.slide_induction[cluster_name]["template_id"] = template_id
162 self.slide_induction[cluster_name]["slides"] = slide_indexs
163
164 @tenacity
165 def content_induct(self):

Callers 1

layout_inductMethod · 0.95

Calls 4

get_image_embeddingFunction · 0.90
images_cosine_similarityFunction · 0.90
get_clusterFunction · 0.90
get_content_typeMethod · 0.45

Tested by

no test coverage detected