Spaces:
Running
Running
Update gen_poster.py
Browse files- gen_poster.py +44 -44
gen_poster.py
CHANGED
|
@@ -24,7 +24,7 @@ def load_config():
|
|
| 24 |
"api_keys": {
|
| 25 |
"gemini_api_key": api_key
|
| 26 |
},
|
| 27 |
-
"api_base_url": api_base_url
|
| 28 |
}
|
| 29 |
|
| 30 |
if api_key:
|
|
@@ -93,9 +93,9 @@ def main():
|
|
| 93 |
continue # 只处理存在 auto 文件夹的目录
|
| 94 |
|
| 95 |
# ✅ 如果 success.txt 已存在,跳过该目录
|
| 96 |
-
success_flag = os.path.join(auto_path, "
|
| 97 |
if os.path.isfile(success_flag):
|
| 98 |
-
print(f"✅
|
| 99 |
continue
|
| 100 |
|
| 101 |
print(f"\n🚀 Processing paper folder: {auto_path}")
|
|
@@ -180,86 +180,86 @@ def main():
|
|
| 180 |
# # === Refiner ===
|
| 181 |
# refinement_ppt(input_index=auto_path, prompts=[commenter_prompt, reviser_prompt], model=model_name, max_iterations=3, config=config)
|
| 182 |
|
| 183 |
-
#
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
|
| 201 |
-
|
| 202 |
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
|
| 208 |
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
|
| 220 |
|
| 221 |
-
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
-
|
| 227 |
|
| 228 |
-
|
| 229 |
|
| 230 |
|
| 231 |
-
# ============================= PR部分 ================================
|
| 232 |
-
pr_template_path="./pr_template.md"
|
| 233 |
-
basic_information_path = extract_basic_information(dag_path=dag_path, auto_path=auto_path,extract_basic_information_prompt=extract_basic_information_prompt,model=model_name, config=config)
|
| 234 |
|
| 235 |
-
initialize_pr_markdown(basic_information_path=basic_information_path,auto_path=auto_path,pr_template_path=pr_template_path)
|
| 236 |
|
| 237 |
-
pr_path=os.path.join(auto_path, "markdown.md")
|
| 238 |
|
| 239 |
|
| 240 |
-
generate_pr_from_dag(dag_path=dag_path, pr_path=pr_path, generate_pr_prompt=generate_pr_prompt, model=model_name, config=config)
|
| 241 |
-
print(f"📝 PR generated at: {pr_path}")
|
| 242 |
|
| 243 |
-
add_title_and_hashtag(pr_path=pr_path, add_title_and_hashtag_prompt=add_title_and_hashtag_prompt, model=model_name, config=config)
|
| 244 |
-
add_institution_tag(pr_path=pr_path)
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
-
dedup_consecutive_markdown_images(pr_path, inplace=True)
|
| 249 |
|
| 250 |
-
print(f"✅ PR markdown post-processed.")
|
| 251 |
|
| 252 |
-
print(f"🖊️ Refining PR markdown with LLM...")
|
| 253 |
-
pr_refine_path=os.path.join(auto_path, "markdown_refined.md")
|
| 254 |
|
| 255 |
-
refinement_pr(pr_path=pr_path, pr_refine_path=pr_refine_path, prompts=pr_refinement_prompt, model=model_name, config=config)
|
| 256 |
-
print (f"✅ PR markdown refined.")
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
# =============================================================
|
| 261 |
# 在auto目录下创建success.txt作为标志
|
| 262 |
-
success_file_path = os.path.join(auto_path, "
|
| 263 |
open(success_file_path, "w").close()
|
| 264 |
|
| 265 |
|
|
|
|
| 24 |
"api_keys": {
|
| 25 |
"gemini_api_key": api_key
|
| 26 |
},
|
| 27 |
+
"api_base_url": api_base_url # <--- ✅ 放在这里才对!
|
| 28 |
}
|
| 29 |
|
| 30 |
if api_key:
|
|
|
|
| 93 |
continue # 只处理存在 auto 文件夹的目录
|
| 94 |
|
| 95 |
# ✅ 如果 success.txt 已存在,跳过该目录
|
| 96 |
+
success_flag = os.path.join(auto_path, "success_poster.txt")
|
| 97 |
if os.path.isfile(success_flag):
|
| 98 |
+
print(f"✅ success_poster.txt exists in {auto_path}, skipping...")
|
| 99 |
continue
|
| 100 |
|
| 101 |
print(f"\n🚀 Processing paper folder: {auto_path}")
|
|
|
|
| 180 |
# # === Refiner ===
|
| 181 |
# refinement_ppt(input_index=auto_path, prompts=[commenter_prompt, reviser_prompt], model=model_name, max_iterations=3, config=config)
|
| 182 |
|
| 183 |
+
# ============================= Poster部分 ================================
|
| 184 |
|
| 185 |
+
poster_outline_path = os.path.join(auto_path, "poster_outline.txt")
|
| 186 |
|
| 187 |
+
print(f"📝 Generating poster outline at: {poster_outline_path}")
|
| 188 |
+
generate_poster_outline_txt(dag_path=dag_path,poster_outline_path=poster_outline_path,poster_outline_prompt=poster_outline_prompt,model=model_name, config=config)
|
| 189 |
+
print (f"✅ Poster outline generated.")
|
| 190 |
|
| 191 |
|
| 192 |
+
poster_path=os.path.join(auto_path, "poster.html")
|
| 193 |
|
| 194 |
|
| 195 |
+
subdir_name = Path(subdir_path).name
|
| 196 |
+
poster_outline_path_modified = os.path.join(auto_path, "poster_outline_modified.txt")
|
| 197 |
+
print(f"📝 Modifying poster outline for paper: {subdir_name}")
|
| 198 |
+
modify_poster_outline(poster_outline_path=poster_outline_path,poster_paper_name=subdir_name,modified_poster_outline_path=poster_outline_path_modified)
|
| 199 |
+
print (f"✅ Poster outline modified.")
|
| 200 |
|
| 201 |
+
modified_poster_logic(poster_outline_path_modified, modified_poster_logic_prompt, model=model_name, config=config)
|
| 202 |
|
| 203 |
|
| 204 |
+
print(f"🖼️ Building poster HTML at: {poster_path}")
|
| 205 |
+
build_poster_from_outline(poster_outline_path=poster_outline_path_modified,poster_template_path="./poster_template/poster_template.html",poster_path=poster_path,)
|
| 206 |
+
print (f"✅ Poster HTML built.")
|
| 207 |
|
| 208 |
|
| 209 |
+
print(f"🖊️ Modifying title and authors in poster HTML...")
|
| 210 |
+
modify_title_and_author(dag_path=dag_path,poster_path=poster_path)
|
| 211 |
+
print (f"✅ Title and authors modified.")
|
| 212 |
|
| 213 |
|
| 214 |
+
poster_final_index = os.path.join(auto_path, "final")
|
| 215 |
+
os.makedirs(poster_final_index, exist_ok=True)
|
| 216 |
|
| 217 |
+
poster_final_output_path = os.path.join(poster_final_index, "poster_final.html")
|
| 218 |
+
print(f"🖊️ Refining poster HTML with Gemini...")
|
| 219 |
|
| 220 |
|
| 221 |
+
out = inject_img_section_to_poster(figure_path="./poster_template/expore_our_work_in_detail.jpg",auto_path=auto_path,poster_path=poster_path)
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
+
refinement_poster(input_html_path=poster_path, prompts=poster_refinement_prompt,output_html_path=poster_final_output_path,model=model_name, config=config)
|
| 227 |
|
| 228 |
+
print (f"✅ Poster HTML refined. Final poster at: {poster_final_output_path}")
|
| 229 |
|
| 230 |
|
| 231 |
+
# # ============================= PR部分 ================================
|
| 232 |
+
# pr_template_path="./pr_template.md"
|
| 233 |
+
# basic_information_path = extract_basic_information(dag_path=dag_path, auto_path=auto_path,extract_basic_information_prompt=extract_basic_information_prompt,model=model_name, config=config)
|
| 234 |
|
| 235 |
+
# initialize_pr_markdown(basic_information_path=basic_information_path,auto_path=auto_path,pr_template_path=pr_template_path)
|
| 236 |
|
| 237 |
+
# pr_path=os.path.join(auto_path, "markdown.md")
|
| 238 |
|
| 239 |
|
| 240 |
+
# generate_pr_from_dag(dag_path=dag_path, pr_path=pr_path, generate_pr_prompt=generate_pr_prompt, model=model_name, config=config)
|
| 241 |
+
# print(f"📝 PR generated at: {pr_path}")
|
| 242 |
|
| 243 |
+
# add_title_and_hashtag(pr_path=pr_path, add_title_and_hashtag_prompt=add_title_and_hashtag_prompt, model=model_name, config=config)
|
| 244 |
+
# add_institution_tag(pr_path=pr_path)
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
+
# dedup_consecutive_markdown_images(pr_path, inplace=True)
|
| 249 |
|
| 250 |
+
# print(f"✅ PR markdown post-processed.")
|
| 251 |
|
| 252 |
+
# print(f"🖊️ Refining PR markdown with LLM...")
|
| 253 |
+
# pr_refine_path=os.path.join(auto_path, "markdown_refined.md")
|
| 254 |
|
| 255 |
+
# refinement_pr(pr_path=pr_path, pr_refine_path=pr_refine_path, prompts=pr_refinement_prompt, model=model_name, config=config)
|
| 256 |
+
# print (f"✅ PR markdown refined.")
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
# =============================================================
|
| 261 |
# 在auto目录下创建success.txt作为标志
|
| 262 |
+
success_file_path = os.path.join(auto_path, "success_poster.txt")
|
| 263 |
open(success_file_path, "w").close()
|
| 264 |
|
| 265 |
|