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

Function parse_raw

demo/Paper2Poster/PosterAgent/parse_raw.py:62–170  ·  view source on GitHub ↗
(args, actor_config, version=2)

Source from the content-addressed store, hash-verified

60 raise RuntimeError("Failed to parse JSON from response", e)
61@retry(stop=stop_after_attempt(5))
62def parse_raw(args, actor_config, version=2):
63 raw_source = args.poster_path
64 markdown_clean_pattern = re.compile(r"<!--[\s\S]*?-->")
65 print(f'\nParsing raw content from {raw_source}...\n')
66 try:
67 raw_result = doc_converter.convert(raw_source)
68 print('✅ PDF converted to document format.')
69 raw_markdown = raw_result.document.export_to_markdown()
70 text_content = markdown_clean_pattern.sub("", raw_markdown)
71 print(f'Extracted {len(text_content)} characters from the document.')
72 if len(text_content) < 500:
73 print('\nParsing with docling failed, using marker instead\n')
74 parser_model = create_model_dict(device='cuda', dtype=torch.float16)
75 text_content, rendered = parse_pdf(raw_source, model_lst=parser_model, save_file=False)
76 except Exception as e:
77 print(f'❌ PDF parsing failed: {e}')
78 raise e
79
80 # Load prompt template safely
81 try:
82 if version == 1:
83 template = Template(open("utils/prompts/gen_poster_raw_content.txt").read())
84 elif version == 2:
85 print('Using v2 prompt template')
86 template = Template(open("utils/prompts/gen_poster_raw_content_v2.txt").read())
87 else:
88 raise ValueError("Invalid version number.")
89 except Exception as e:
90 print(f'❌ Failed to load prompt template: {e}')
91 raise e
92
93 # Initialize actor model
94 try:
95 if args.model_name_t.startswith('vllm_qwen'):
96 actor_model = ModelFactory.create(
97 model_platform=actor_config['model_platform'],
98 model_type=actor_config['model_type'],
99 model_config_dict=actor_config['model_config'],
100 url=actor_config['url'],
101 )
102 else:
103 actor_model = ModelFactory.create(
104 model_platform=actor_config['model_platform'],
105 model_type=actor_config['model_type'],
106 model_config_dict=actor_config['model_config'],
107 )
108
109 actor_sys_msg = 'You are the author of the paper, and you will create a poster for the paper.'
110 actor_agent = ChatAgent(
111 system_message=actor_sys_msg,
112 model=actor_model,
113 message_window_size=10,
114 token_limit=actor_config.get('token_limit', None)
115 )
116 except Exception as e:
117 print(f'❌ Failed to initialize actor model: {e}')
118 raise e
119

Callers 3

new_pipeline.pyFile · 0.90
parse_raw.pyFile · 0.70

Calls 9

resetMethod · 0.95
stepMethod · 0.95
parse_pdfFunction · 0.90
ChatAgentClass · 0.90
account_tokenFunction · 0.70
get_json_from_responseFunction · 0.70
convertMethod · 0.45
subMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected