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

Function gen_eval_markdown

utils/poster_eval_utils.py:1045–1181  ·  view source on GitHub ↗
(paper_name, poster_method, poster_path, figure_count_only=False)

Source from the content-addressed store, hash-verified

1043 return records
1044
1045def gen_eval_markdown(paper_name, poster_method, poster_path, figure_count_only=False):
1046 model_name="openai/clip-vit-base-patch32"
1047 model_name = "BAAI/AltCLIP"
1048 model = AltCLIPModel.from_pretrained(model_name).to('cuda')
1049 processor = AltCLIPProcessor.from_pretrained(model_name)
1050
1051 # create a uniquely‐named file in your system temp dir (or specify dir="tmp")
1052 with tempfile.NamedTemporaryFile(suffix=".pdf", prefix="poster_", dir="tmp", delete=False) as tf:
1053 unique_pdf = tf.name
1054
1055 if poster_method != 'paper':
1056 # convert into that file
1057 png_to_pdf(poster_path, unique_pdf)
1058 poster_path = unique_pdf
1059 IMAGE_RESOLUTION_SCALE = 5.0
1060 agent_name = f'image_captioner'
1061 with open(f"utils/prompt_templates/{agent_name}.yaml", "r") as f:
1062 config = yaml.safe_load(f)
1063 actor_model = ModelFactory.create(
1064 model_platform=ModelPlatformType.OPENAI,
1065 model_type=ModelType.GPT_4O,
1066 model_config_dict=ChatGPTConfig().as_dict(), # [Optional] the config for model
1067 )
1068
1069 actor_sys_msg = config['system_prompt']
1070
1071 actor_agent = ChatAgent(
1072 system_message=actor_sys_msg,
1073 model=actor_model,
1074 message_window_size=None,
1075 )
1076 jinja_env = Environment(undefined=StrictUndefined)
1077
1078 template = jinja_env.from_string(config["template"])
1079 prompt = template.render()
1080
1081 raw_source = poster_path
1082 converter = DocumentConverter()
1083 raw_result = converter.convert(raw_source)
1084 raw_markdown = raw_result.document.export_to_markdown()
1085
1086 output_dir = Path(f'eval_poster_markdown/{paper_name}/{poster_method}')
1087 output_dir.mkdir(parents=True, exist_ok=True)
1088
1089 pipeline_options = PdfPipelineOptions()
1090 pipeline_options.images_scale = IMAGE_RESOLUTION_SCALE
1091 pipeline_options.generate_page_images = True
1092 pipeline_options.generate_picture_images = True
1093
1094 doc_converter = DocumentConverter(
1095 format_options={
1096 InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
1097 }
1098 )
1099
1100 conv_res = doc_converter.convert(raw_source)
1101
1102 output_dir.mkdir(parents=True, exist_ok=True)

Callers 1

Calls 15

convertMethod · 0.95
stepMethod · 0.95
resetMethod · 0.95
ChatGPTConfigClass · 0.90
ChatAgentClass · 0.90
DocumentConverterClass · 0.90
PdfPipelineOptionsClass · 0.90
PdfFormatOptionClass · 0.90
png_to_pdfFunction · 0.70
compute_clip_embeddingFunction · 0.70
get_poster_textFunction · 0.70

Tested by

no test coverage detected