()
| 310 | |
| 311 | |
| 312 | def dataset_stat(): |
| 313 | pdf_stat = {} |
| 314 | ppt_stat = {} |
| 315 | tempdir = tempfile.TemporaryDirectory() |
| 316 | config = Config() |
| 317 | config.set_rundir(tempdir.name) |
| 318 | for topic in topics: |
| 319 | markdown_contents = { |
| 320 | f: len(open(f, "r").read()) for f in glob(f"data/{topic}/pdf/*/*.md") |
| 321 | } |
| 322 | pdf_stat |= markdown_contents |
| 323 | avg_pdf_text_len = sum(markdown_contents.values()) / len(markdown_contents) |
| 324 | num_images = 0 |
| 325 | for pdf_folder in glob(f"data/{topic}/pdf/*"): |
| 326 | images = json.load(open(os.path.join(pdf_folder, "image_caption.json"))) |
| 327 | num_images += len(images) |
| 328 | avg_pdf_images = num_images / len(markdown_contents) |
| 329 | ppt_text_len = 0 |
| 330 | ppt_pages = 0 |
| 331 | ppt_images = 0 |
| 332 | num_ppts = 10 |
| 333 | for ppt_folder in glob(f"data/{topic}/pptx/*"): |
| 334 | presentation = Presentation.from_file( |
| 335 | os.path.join(ppt_folder, "source.pptx"), config |
| 336 | ) |
| 337 | ppt_stat[ppt_folder] = sum( |
| 338 | [len(slide.to_text()) for slide in presentation.slides] |
| 339 | ) |
| 340 | |
| 341 | ppt_text_len += ppt_stat[ppt_folder] |
| 342 | ppt_pages += len(presentation) |
| 343 | ppt_images += len(os.listdir(os.path.join(ppt_folder, "images"))) |
| 344 | |
| 345 | avg_ppt_pages = ppt_pages / num_ppts |
| 346 | avg_ppt_text_len = ppt_text_len / num_ppts |
| 347 | avg_ppt_images = ppt_images / num_ppts |
| 348 | print( |
| 349 | "topic", |
| 350 | "avg_pdf_text_len", |
| 351 | "avg_pdf_images", |
| 352 | "avg_ppt_pages", |
| 353 | "avg_ppt_images", |
| 354 | "avg_ppt_text_len", |
| 355 | ) |
| 356 | print( |
| 357 | f"{topic}: {avg_pdf_text_len:.2f}, {avg_pdf_images:.2f}, {avg_ppt_pages:.2f}, {avg_ppt_images:.2f}, {avg_ppt_text_len:.2f}" |
| 358 | ) |
| 359 | |
| 360 | json.dump( |
| 361 | {"pdf": pdf_stat, "ppt": ppt_stat}, open("data/eval/stat.json", "w"), indent=4 |
| 362 | ) |
| 363 | |
| 364 | |
| 365 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected