Laramie2 commited on
Commit
6846f04
·
verified ·
1 Parent(s): 1cc4cd9

Update gen_dag.py

Browse files
Files changed (1) hide show
  1. gen_dag.py +47 -42
gen_dag.py CHANGED
@@ -12,7 +12,7 @@ def load_config():
12
  """
13
  base_dir = os.path.dirname(os.path.abspath(__file__))
14
 
15
- # 获取由 app.py 注入的专属输出文件夹,如果没有则回退到本地默认文件夹(方便本地调试)
16
  user_root_folder = os.environ.get("USER_OUTPUT_DIR", os.path.join(base_dir, "mineru_outputs"))
17
 
18
  # 获取由 app.py 注入的 API 凭证
@@ -50,16 +50,18 @@ def load_prompt(prompt_path="prompt.json", prompt_name="poster_prompt"):
50
  data = json.load(f)
51
  return data.get(prompt_name, "")
52
 
53
- # 应用配置 (此时 config 已经在内存中组装好了)
54
  config = load_config()
 
55
  model_name = config['model_settings']['generation_model']
56
 
57
  # ========== 主流程 ==========
58
  def main():
59
- # 这里的 root_folder 现在指向的是当前用户的专属 mineru_outputs 文件夹
60
  root_folder = config['path']['root_folder']
61
  prompt_path = "prompt.json"
62
 
 
63
  print("📘 Loading prompts...")
64
  # dag prompt:
65
  section_split_prompt = load_prompt(prompt_path, prompt_name="section_split_prompt")
@@ -86,6 +88,9 @@ def main():
86
  add_title_and_hashtag_prompt = load_prompt(prompt_path, prompt_name="add_title_and_hashtag_prompt")
87
  pr_refinement_prompt = load_prompt(prompt_path, prompt_name="pr_refinement_prompt")
88
 
 
 
 
89
  # === 遍历每个子文件夹 ===
90
  for subdir in os.listdir(root_folder):
91
  subdir_path = os.path.join(root_folder, subdir)
@@ -124,64 +129,64 @@ def main():
124
  output_html = os.path.join(auto_path, "poster.html")
125
  graph_json_path = os.path.join(auto_path, "graph.json")
126
 
127
- # # === 清理 markdown === 去除无意义的段落,如relative work,reference,appendix等等
128
- # print("🧹 Cleaning markdown before splitting...")
129
- # cleaned_md_path = clean_paper(md_path, clean_prompt, model="gemini-3-pro-preview", config=config)
130
 
131
- # # === 利用gpt将论文分段 ===
132
- # paths = split_paper(cleaned_md_path, section_split_prompt, model="gemini-3-pro-preview" ,config=config)
133
 
134
- # # === 利用gpt初始化dag ===
135
- # dag = initialize_dag(markdown_path=cleaned_md_path,initialize_dag_prompt=initialize_dag_prompt,model="gemini-3-pro-preview", config=config)
136
  dag_path = os.path.join(auto_path, "dag.json")
137
 
138
 
139
- # # === 生成visual_dag ===
140
- # visual_dag_path=os.path.join(auto_path, "visual_dag.json")
141
- # extract_and_generate_visual_dag(markdown_path=cleaned_md_path,prompt_for_gpt=visual_dag_prompt,output_json_path=visual_dag_path,model="gemini-3-pro-preview", config=config)
142
- # add_resolution_to_visual_dag(auto_path, visual_dag_path)
143
 
144
- # # === 生成section_dag ===
145
- # section_split_output_path=os.path.join(subdir_path, "section_split_output")
146
- # build_section_dags(folder_path=section_split_output_path,base_prompt=section_dag_generation_prompt,model="gemini-3-pro-preview", config=config)
147
 
148
 
149
- # # === 向dag.json添加section_dag ===
150
- # section_dag_path=os.path.join(subdir_path, "section_dag")
151
- # merged_path = add_section_dag(section_dag_folder=section_dag_path,main_dag_path=dag_path,output_path=None)
152
 
153
- # # === 向dag.json添加visual_dag ===
154
- # add_visual_dag(dag_path=dag_path,visual_dag_path=visual_dag_path)
155
 
156
- # # === 完善dag中每一个结点的visual_node ===
157
- # refine_visual_node(dag_path)
158
 
159
 
160
 
161
 
162
- # ============================= PPT部分 ================================
163
 
164
- # === 按照算法选出结点,以便后续生成outline ===
165
- selected_node_path=os.path.join(auto_path, "selected_node.json")
166
- generate_selected_nodes(dag_json_path=dag_path, max_len=15,output_path=selected_node_path)
167
 
168
- # === 初始化ouline ===
169
- outline_path= os.path.join(auto_path, "outline.json")
170
- outline = outline_initialize(dag_json_path=dag_path,outline_initialize_prompt=outline_initialize_prompt,model=model_name, config=config)
171
 
172
- # === 生成完整ouline ===
173
- outline_data=generate_complete_outline(selected_node_path,outline_path,generate_complete_outline_prompt,model=model_name, config=config)
174
 
175
- # === 配模板 ===
176
- arrange_template(outline_path,arrange_template_prompt,model=model_name, config=config)
177
 
178
- # === 生成最终的PPT ===
179
- ppt_template_path="./ppt_template"
180
- generate_ppt_prompt = {"role":"system","content":"You are given (1) a slide node (JSON) and (2) an HTML slide template. Your task: revise the HTML template to produce the final slide HTML using the node content. Node fields: text (slide textual content), figure (list of images to display, each has name, caption, resolution), formula (list of formula images to display, each has name, caption, resolution), template (template filename). IMPORTANT RULES: 1) Only modify places in the HTML that are marked by comments like . 2) For 'Subjects' sections: replace the placeholder title with ONE concise summary sentence for this slide. 3) For 'Image' sections (<img ...>): replace src with the relative path extracted from node.figure/formula[i].name; the node image name may be markdown like '![](images/abc.jpg)', use only 'images/abc.jpg'. 4) For 'Text' sections: replace the placeholder text with the node.text content, formatted cleanly in HTML; keep it readable and you may use <p>, <ul><li>, <br/> appropriately. 5) If the template expects more images/text blocks than provided by the node, leave the missing positions unchanged and do not invent content. 6) If the node provides more images than the template has slots, fill slots in order and ignore the rest. 7) Preserve all other HTML, CSS, and structure exactly. OUTPUT FORMAT: Return ONLY the revised HTML as plain text. Do NOT wrap it in markdown fences. Do NOT add explanations."}
181
- generate_ppt(outline_path,ppt_template_path,generate_ppt_prompt,model=model_name, config=config)
182
 
183
- # === Refiner ===
184
- refinement_ppt(input_index=auto_path, prompts=[commenter_prompt, reviser_prompt], model=model_name, max_iterations=3, config=config)
185
 
186
  # # ============================= Poster部分 ================================
187
 
@@ -262,7 +267,7 @@ def main():
262
 
263
  # =============================================================
264
  # 在auto目录下创建success.txt作为标志
265
- success_file_path = os.path.join(auto_path, "success_ppt.txt")
266
  open(success_file_path, "w").close()
267
 
268
 
 
12
  """
13
  base_dir = os.path.dirname(os.path.abspath(__file__))
14
 
15
+ # 获取由 app.py 注入的专属输出文件夹,如果没有则回退到本地默认文件夹(方便本地单独运行调试)
16
  user_root_folder = os.environ.get("USER_OUTPUT_DIR", os.path.join(base_dir, "mineru_outputs"))
17
 
18
  # 获取由 app.py 注入的 API 凭证
 
50
  data = json.load(f)
51
  return data.get(prompt_name, "")
52
 
53
+ # 应用配置
54
  config = load_config()
55
+
56
  model_name = config['model_settings']['generation_model']
57
 
58
  # ========== 主流程 ==========
59
  def main():
60
+ # 输入总文件夹路径(包含多个论文子文件夹)此时指向用户的专属文件夹
61
  root_folder = config['path']['root_folder']
62
  prompt_path = "prompt.json"
63
 
64
+
65
  print("📘 Loading prompts...")
66
  # dag prompt:
67
  section_split_prompt = load_prompt(prompt_path, prompt_name="section_split_prompt")
 
88
  add_title_and_hashtag_prompt = load_prompt(prompt_path, prompt_name="add_title_and_hashtag_prompt")
89
  pr_refinement_prompt = load_prompt(prompt_path, prompt_name="pr_refinement_prompt")
90
 
91
+
92
+
93
+
94
  # === 遍历每个子文件夹 ===
95
  for subdir in os.listdir(root_folder):
96
  subdir_path = os.path.join(root_folder, subdir)
 
129
  output_html = os.path.join(auto_path, "poster.html")
130
  graph_json_path = os.path.join(auto_path, "graph.json")
131
 
132
+ # === 清理 markdown === 去除无意义的段落,如relative work,reference,appendix等等
133
+ print("🧹 Cleaning markdown before splitting...")
134
+ cleaned_md_path = clean_paper(md_path, clean_prompt, model="gemini-3-pro-preview", config=config)
135
 
136
+ # === 利用gpt将论文分段 ===
137
+ paths = split_paper(cleaned_md_path, section_split_prompt, model="gemini-3-pro-preview" ,config=config)
138
 
139
+ # === 利用gpt初始化dag ===
140
+ dag = initialize_dag(markdown_path=cleaned_md_path,initialize_dag_prompt=initialize_dag_prompt,model="gemini-3-pro-preview", config=config)
141
  dag_path = os.path.join(auto_path, "dag.json")
142
 
143
 
144
+ # === 生成visual_dag ===
145
+ visual_dag_path=os.path.join(auto_path, "visual_dag.json")
146
+ extract_and_generate_visual_dag(markdown_path=cleaned_md_path,prompt_for_gpt=visual_dag_prompt,output_json_path=visual_dag_path,model="gemini-3-pro-preview", config=config)
147
+ add_resolution_to_visual_dag(auto_path, visual_dag_path)
148
 
149
+ # === 生成section_dag ===
150
+ section_split_output_path=os.path.join(subdir_path, "section_split_output")
151
+ build_section_dags(folder_path=section_split_output_path,base_prompt=section_dag_generation_prompt,model="gemini-3-pro-preview", config=config)
152
 
153
 
154
+ # === 向dag.json添加section_dag ===
155
+ section_dag_path=os.path.join(subdir_path, "section_dag")
156
+ merged_path = add_section_dag(section_dag_folder=section_dag_path,main_dag_path=dag_path,output_path=None)
157
 
158
+ # === 向dag.json添加visual_dag ===
159
+ add_visual_dag(dag_path=dag_path,visual_dag_path=visual_dag_path)
160
 
161
+ # === 完善dag中每一个结点的visual_node ===
162
+ refine_visual_node(dag_path)
163
 
164
 
165
 
166
 
167
+ # # ============================= PPT部分 ================================
168
 
169
+ # # === 按照算法选出结点,以便后续生成outline ===
170
+ # selected_node_path=os.path.join(auto_path, "selected_node.json")
171
+ # generate_selected_nodes(dag_json_path=dag_path, max_len=15,output_path=selected_node_path)
172
 
173
+ # # === 初始化ouline ===
174
+ # outline_path= os.path.join(auto_path, "outline.json")
175
+ # outline = outline_initialize(dag_json_path=dag_path,outline_initialize_prompt=outline_initialize_prompt,model=model_name, config=config)
176
 
177
+ # # === 生成完整ouline ===
178
+ # outline_data=generate_complete_outline(selected_node_path,outline_path,generate_complete_outline_prompt,model=model_name, config=config)
179
 
180
+ # # === 配模板 ===
181
+ # arrange_template(outline_path,arrange_template_prompt,model=model_name, config=config)
182
 
183
+ # # === 生成最终的PPT ===
184
+ # ppt_template_path="./ppt_template"
185
+ # generate_ppt_prompt = {"role":"system","content":"You are given (1) a slide node (JSON) and (2) an HTML slide template. Your task: revise the HTML template to produce the final slide HTML using the node content. Node fields: text (slide textual content), figure (list of images to display, each has name, caption, resolution), formula (list of formula images to display, each has name, caption, resolution), template (template filename). IMPORTANT RULES: 1) Only modify places in the HTML that are marked by comments like . 2) For 'Subjects' sections: replace the placeholder title with ONE concise summary sentence for this slide. 3) For 'Image' sections (<img ...>): replace src with the relative path extracted from node.figure/formula[i].name; the node image name may be markdown like '![](images/abc.jpg)', use only 'images/abc.jpg'. 4) For 'Text' sections: replace the placeholder text with the node.text content, formatted cleanly in HTML; keep it readable and you may use <p>, <ul><li>, <br/> appropriately. 5) If the template expects more images/text blocks than provided by the node, leave the missing positions unchanged and do not invent content. 6) If the node provides more images than the template has slots, fill slots in order and ignore the rest. 7) Preserve all other HTML, CSS, and structure exactly. OUTPUT FORMAT: Return ONLY the revised HTML as plain text. Do NOT wrap it in markdown fences. Do NOT add explanations."}
186
+ # generate_ppt(outline_path,ppt_template_path,generate_ppt_prompt,model=model_name, config=config)
187
 
188
+ # # === Refiner ===
189
+ # refinement_ppt(input_index=auto_path, prompts=[commenter_prompt, reviser_prompt], model=model_name, max_iterations=3, config=config)
190
 
191
  # # ============================= Poster部分 ================================
192
 
 
267
 
268
  # =============================================================
269
  # 在auto目录下创建success.txt作为标志
270
+ success_file_path = os.path.join(auto_path, "success_dag.txt")
271
  open(success_file_path, "w").close()
272
 
273