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

Function poster_apply_theme

PosterAgent/apply_theme.py:23–261  ·  view source on GitHub ↗
(args, actor_config, critic_config)

Source from the content-addressed store, hash-verified

21load_dotenv()
22
23def poster_apply_theme(args, actor_config, critic_config):
24 total_input_token, total_output_token = 0, 0
25 extract_input_token, extract_output_token = 0, 0
26 gen_input_token, gen_output_token = 0, 0
27 non_overlap_ckpt = pkl.load(open(f'checkpoints/{args.model_name}_{args.poster_name}_non_overlap_ckpt_{args.index}.pkl', 'rb'))
28 non_overlap_code = non_overlap_ckpt['final_code_by_section']
29 sections = list(non_overlap_code.keys())
30 sections = [s for s in sections if s != 'meta']
31 template_img = convert_from_path(args.template_path)[0]
32 image_bytes = io.BytesIO()
33 template_img.save(image_bytes, format="PNG")
34 image_bytes.seek(0)
35
36 # Reload the image from memory as a standard PIL.Image.Image
37 template_img = Image.open(image_bytes)
38
39
40 title_actor_agent_name = 'theme_agent_title'
41 with open(f"prompt_templates/{title_actor_agent_name}.yaml", "r") as f:
42 title_theme_actor_config = yaml.safe_load(f)
43
44 section_actor_agent_name = 'theme_agent_section'
45 with open(f"prompt_templates/{section_actor_agent_name}.yaml", "r") as f:
46 section_theme_actor_config = yaml.safe_load(f)
47
48 title_actor_model = ModelFactory.create(
49 model_platform=actor_config['model_platform'],
50 model_type=actor_config['model_type'],
51 model_config_dict=actor_config['model_config'], # [Optional] the config for model
52 )
53
54 title_actor_sys_msg = title_theme_actor_config['system_prompt']
55
56 title_actor_agent = ChatAgent(
57 system_message=title_actor_sys_msg,
58 model=title_actor_model,
59 message_window_size=10, # [Optional] the length for chat memory
60 )
61
62 section_actor_model = ModelFactory.create(
63 model_platform=actor_config['model_platform'],
64 model_type=actor_config['model_type'],
65 model_config_dict=actor_config['model_config'], # [Optional] the config for model
66 )
67
68 section_actor_sys_msg = section_theme_actor_config['system_prompt']
69
70 section_actor_agent = ChatAgent(
71 system_message=section_actor_sys_msg,
72 model=section_actor_model,
73 message_window_size=10, # [Optional] the length for chat memory
74 )
75
76 critic_model = ModelFactory.create(
77 model_platform=critic_config['model_platform'],
78 model_type=critic_config['model_type'],
79 model_config_dict=critic_config['model_config'],
80 )

Callers 2

apply_theme.pyFile · 0.70

Calls 13

resetMethod · 0.95
stepMethod · 0.95
ChatAgentClass · 0.90
get_json_from_responseFunction · 0.90
ppt_to_imagesFunction · 0.90
apply_themeFunction · 0.85
account_tokenFunction · 0.50
loadMethod · 0.45
saveMethod · 0.45
createMethod · 0.45
make_user_messageMethod · 0.45
from_stringMethod · 0.45

Tested by

no test coverage detected