Spaces:
Sleeping
Sleeping
Update gen_pr.py
Browse files
gen_pr.py
CHANGED
|
@@ -4,13 +4,44 @@ from pathlib import Path
|
|
| 4 |
|
| 5 |
from src import *
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return config
|
| 15 |
|
| 16 |
# ========== 读取 prompt 模板 ==========
|
|
@@ -26,8 +57,8 @@ model_name = config['model_settings']['generation_model']
|
|
| 26 |
|
| 27 |
# ========== 主流程 ==========
|
| 28 |
def main():
|
| 29 |
-
# 输入总文件夹路径(包含多个论文子文件夹)
|
| 30 |
-
root_folder = config['path']['root_folder']
|
| 31 |
prompt_path = "prompt.json"
|
| 32 |
|
| 33 |
|
|
@@ -98,7 +129,7 @@ def main():
|
|
| 98 |
output_html = os.path.join(auto_path, "poster.html")
|
| 99 |
graph_json_path = os.path.join(auto_path, "graph.json")
|
| 100 |
|
| 101 |
-
# # === 清理 markdown ===
|
| 102 |
# print("🧹 Cleaning markdown before splitting...")
|
| 103 |
# cleaned_md_path = clean_paper(md_path, clean_prompt, model="gemini-3-pro-preview", config=config)
|
| 104 |
|
|
@@ -133,29 +164,29 @@ def main():
|
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
-
# #
|
| 137 |
|
| 138 |
-
# #
|
| 139 |
-
#
|
| 140 |
-
#
|
| 141 |
|
| 142 |
-
# #
|
| 143 |
-
#
|
| 144 |
-
#
|
| 145 |
|
| 146 |
-
# #
|
| 147 |
-
#
|
| 148 |
|
| 149 |
-
# #
|
| 150 |
-
#
|
| 151 |
|
| 152 |
-
# #
|
| 153 |
-
#
|
| 154 |
-
#
|
| 155 |
-
#
|
| 156 |
|
| 157 |
-
# #
|
| 158 |
-
#
|
| 159 |
|
| 160 |
# # ============================= Poster部分 ================================
|
| 161 |
|
|
@@ -236,7 +267,7 @@ def main():
|
|
| 236 |
|
| 237 |
# =============================================================
|
| 238 |
# 在auto目录下创建success.txt作为标志
|
| 239 |
-
success_file_path = os.path.join(auto_path, "
|
| 240 |
open(success_file_path, "w").close()
|
| 241 |
|
| 242 |
|
|
|
|
| 4 |
|
| 5 |
from src import *
|
| 6 |
|
| 7 |
+
# ============= 从环境变量动态生成配置 ===============
|
| 8 |
+
def load_config():
|
| 9 |
+
"""
|
| 10 |
+
不再读取 config.yaml,而是从 Gradio 主程序注入的环境变量中获取专属参数,
|
| 11 |
+
并组装成原有代码期望的字典结构,实现多用户隔离。
|
| 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 凭证
|
| 19 |
+
api_key = os.environ.get("GEMINI_API_KEY", "")
|
| 20 |
+
api_base_url = os.environ.get("GEMINI_API_BASE_URL", "")
|
| 21 |
+
|
| 22 |
+
# 可以在这里设置默认使用的模型,或者也改用环境变量传入
|
| 23 |
+
generation_model = os.environ.get("GENERATION_MODEL", "gemini-3-pro-preview")
|
| 24 |
+
|
| 25 |
+
# 拼装成原版 config.yaml 的字典结构,保证后续代码兼容
|
| 26 |
+
config = {
|
| 27 |
+
"model_settings": {
|
| 28 |
+
"generation_model": generation_model
|
| 29 |
+
},
|
| 30 |
+
"path": {
|
| 31 |
+
"root_folder": user_root_folder
|
| 32 |
+
},
|
| 33 |
+
"api_keys": {
|
| 34 |
+
"gemini_api_key": api_key,
|
| 35 |
+
"api_base_url": api_base_url
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
# 如果你的底层 src 代码库也需要直接用到 os.environ,我们在这里显式注入一下
|
| 40 |
+
if api_key:
|
| 41 |
+
os.environ["GEMINI_API_KEY"] = api_key
|
| 42 |
+
if api_base_url:
|
| 43 |
+
os.environ["GEMINI_API_BASE_URL"] = api_base_url
|
| 44 |
+
|
| 45 |
return config
|
| 46 |
|
| 47 |
# ========== 读取 prompt 模板 ==========
|
|
|
|
| 57 |
|
| 58 |
# ========== 主流程 ==========
|
| 59 |
def main():
|
| 60 |
+
# 输入总文件夹路径(包含多个论文子文件夹)此时指向用户的专属文件夹
|
| 61 |
+
root_folder = config['path']['root_folder']
|
| 62 |
prompt_path = "prompt.json"
|
| 63 |
|
| 64 |
|
|
|
|
| 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 |
|
|
|
|
| 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 '', 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 |
|