ZaynZhu
commited on
Commit
·
f6173f6
1
Parent(s):
92a26f8
add api_key args
Browse files- app.py +8 -6
- pipeline.py +10 -36
app.py
CHANGED
|
@@ -6,25 +6,26 @@ ROOT = Path(__file__).resolve().parent
|
|
| 6 |
OUTPUT_DIR = ROOT / "output"
|
| 7 |
ZIP_PATH = ROOT / "output.zip"
|
| 8 |
|
| 9 |
-
def run_pipeline(model_name_t, model_name_v, result_dir, paper_latex_root, arxiv_url):
|
| 10 |
# 清理旧输出
|
| 11 |
if OUTPUT_DIR.exists():
|
| 12 |
shutil.rmtree(OUTPUT_DIR)
|
| 13 |
if ZIP_PATH.exists():
|
| 14 |
ZIP_PATH.unlink()
|
| 15 |
|
| 16 |
-
#
|
| 17 |
cmd = [
|
| 18 |
"python", "pipeline.py",
|
| 19 |
"--model_name_t", model_name_t,
|
| 20 |
"--model_name_v", model_name_v,
|
| 21 |
"--result_dir", result_dir,
|
| 22 |
"--paper_latex_root", paper_latex_root,
|
| 23 |
-
"--arxiv_url", arxiv_url
|
|
|
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
try:
|
| 27 |
-
# 运行 pipeline
|
| 28 |
result = subprocess.run(cmd, capture_output=True, text=True, timeout=1800)
|
| 29 |
logs = result.stdout + "\n" + result.stderr
|
| 30 |
except subprocess.TimeoutExpired:
|
|
@@ -32,7 +33,6 @@ def run_pipeline(model_name_t, model_name_v, result_dir, paper_latex_root, arxiv
|
|
| 32 |
except Exception as e:
|
| 33 |
return f"❌ Error: {e}", None
|
| 34 |
|
| 35 |
-
# 检查输出目录
|
| 36 |
if not OUTPUT_DIR.exists():
|
| 37 |
return "❌ No output generated.", None
|
| 38 |
|
|
@@ -45,7 +45,7 @@ def run_pipeline(model_name_t, model_name_v, result_dir, paper_latex_root, arxiv
|
|
| 45 |
|
| 46 |
return logs, ZIP_PATH
|
| 47 |
|
| 48 |
-
# Gradio
|
| 49 |
iface = gr.Interface(
|
| 50 |
fn=run_pipeline,
|
| 51 |
inputs=[
|
|
@@ -54,6 +54,8 @@ iface = gr.Interface(
|
|
| 54 |
gr.Textbox(label="Result Dir", value="output"),
|
| 55 |
gr.Textbox(label="Paper LaTeX Root", value="input/latex_proj"),
|
| 56 |
gr.Textbox(label="ArXiv URL", value="https://arxiv.org/abs/2505.21497"),
|
|
|
|
|
|
|
| 57 |
],
|
| 58 |
outputs=[
|
| 59 |
gr.Textbox(label="Logs"),
|
|
|
|
| 6 |
OUTPUT_DIR = ROOT / "output"
|
| 7 |
ZIP_PATH = ROOT / "output.zip"
|
| 8 |
|
| 9 |
+
def run_pipeline(model_name_t, model_name_v, result_dir, paper_latex_root, arxiv_url, openai_key, gemini_key):
|
| 10 |
# 清理旧输出
|
| 11 |
if OUTPUT_DIR.exists():
|
| 12 |
shutil.rmtree(OUTPUT_DIR)
|
| 13 |
if ZIP_PATH.exists():
|
| 14 |
ZIP_PATH.unlink()
|
| 15 |
|
| 16 |
+
# 构造命令(传递两个 key)
|
| 17 |
cmd = [
|
| 18 |
"python", "pipeline.py",
|
| 19 |
"--model_name_t", model_name_t,
|
| 20 |
"--model_name_v", model_name_v,
|
| 21 |
"--result_dir", result_dir,
|
| 22 |
"--paper_latex_root", paper_latex_root,
|
| 23 |
+
"--arxiv_url", arxiv_url,
|
| 24 |
+
"--openai_key", openai_key,
|
| 25 |
+
"--gemini_key", gemini_key
|
| 26 |
]
|
| 27 |
|
| 28 |
try:
|
|
|
|
| 29 |
result = subprocess.run(cmd, capture_output=True, text=True, timeout=1800)
|
| 30 |
logs = result.stdout + "\n" + result.stderr
|
| 31 |
except subprocess.TimeoutExpired:
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"❌ Error: {e}", None
|
| 35 |
|
|
|
|
| 36 |
if not OUTPUT_DIR.exists():
|
| 37 |
return "❌ No output generated.", None
|
| 38 |
|
|
|
|
| 45 |
|
| 46 |
return logs, ZIP_PATH
|
| 47 |
|
| 48 |
+
# ===================== Gradio UI =====================
|
| 49 |
iface = gr.Interface(
|
| 50 |
fn=run_pipeline,
|
| 51 |
inputs=[
|
|
|
|
| 54 |
gr.Textbox(label="Result Dir", value="output"),
|
| 55 |
gr.Textbox(label="Paper LaTeX Root", value="input/latex_proj"),
|
| 56 |
gr.Textbox(label="ArXiv URL", value="https://arxiv.org/abs/2505.21497"),
|
| 57 |
+
gr.Textbox(label="OpenAI API Key", placeholder="sk-...", type="password"),
|
| 58 |
+
gr.Textbox(label="Gemini API Key", placeholder="AIza...", type="password"),
|
| 59 |
],
|
| 60 |
outputs=[
|
| 61 |
gr.Textbox(label="Logs"),
|
pipeline.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# pipeline.py
|
| 2 |
import cv2
|
| 3 |
import pdb
|
| 4 |
import json
|
|
@@ -16,30 +15,20 @@ print("Initializing...")
|
|
| 16 |
|
| 17 |
from Paper2Video.src.slide_code_gen import latex_code_gen
|
| 18 |
from Paper2Video.src.wei_utils import get_agent_config
|
| 19 |
-
|
| 20 |
-
# ✅ 用小写包名
|
| 21 |
from posterbuilder import build_poster as build_poster
|
| 22 |
-
# 取出 build_poster 里用到的图片目录常量,便于推导 JSON 前缀
|
| 23 |
from posterbuilder.build_poster import IMAGES_DIR_NAME
|
| 24 |
|
| 25 |
-
# ----------------- 常用路径 -----------------
|
| 26 |
ROOT_DIR = Path(__file__).resolve().parent
|
| 27 |
P2V_ASSETS = ROOT_DIR / "Paper2Video" / "assets" / "demo" / "latex_proj"
|
| 28 |
P2P_ROOT = ROOT_DIR / "Paper2Poster"
|
| 29 |
PB_ROOT = ROOT_DIR / "posterbuilder"
|
| 30 |
-
|
| 31 |
-
# 允许以包名 PosterAgent.* 方式导入(供潜在直接 import 使用)
|
| 32 |
sys.path.append(str(P2P_ROOT))
|
| 33 |
|
| 34 |
-
os.environ["GEMINI_API_KEY"] = "AIzaSyA1wVVdlYAVs3FULSmCVD1Noulwrq7zqeo"
|
| 35 |
-
os.environ["OPENAI_API_KEY"] = "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"
|
| 36 |
-
|
| 37 |
def copy_folder(src_dir, dst_dir):
|
| 38 |
src_dir = Path(src_dir)
|
| 39 |
dst_dir = Path(dst_dir)
|
| 40 |
if not src_dir.exists():
|
| 41 |
raise FileNotFoundError(f"no such dir: {src_dir}")
|
| 42 |
-
# 若目标存在,先删掉再复制
|
| 43 |
if dst_dir.exists():
|
| 44 |
shutil.rmtree(dst_dir)
|
| 45 |
shutil.copytree(src_dir, dst_dir)
|
|
@@ -58,21 +47,14 @@ def str2list(s):
|
|
| 58 |
return [int(x) for x in s.split(',')]
|
| 59 |
|
| 60 |
def run_paper2poster_content_build():
|
| 61 |
-
"""Step 1.5:
|
| 62 |
-
1) 把 input/paper.pdf 复制到 Paper2Poster/input/paper/paper.pdf
|
| 63 |
-
2) 运行 Paper2Poster 的 PosterAgent.new_pipeline 生成内容
|
| 64 |
-
3) 将 3 个 JSON 拷贝/改名到 posterbuilder/contents/(并在包根再放一份,兼容读取)
|
| 65 |
-
"""
|
| 66 |
print("🧩 Step 1.5: Preparing Paper2Poster inputs & generating poster contents ...")
|
| 67 |
|
| 68 |
-
# 1) 复制 PDF
|
| 69 |
src_pdf = ROOT_DIR / "input" / "paper.pdf"
|
| 70 |
dst_pdf = P2P_ROOT / "input" / "paper" / "paper.pdf"
|
| 71 |
dst_pdf.parent.mkdir(parents=True, exist_ok=True)
|
| 72 |
safe_copy(src_pdf, dst_pdf)
|
| 73 |
print(f" 📄 Copied paper: {src_pdf.relative_to(ROOT_DIR)} → {dst_pdf.relative_to(ROOT_DIR)}")
|
| 74 |
|
| 75 |
-
# 2) 运行 PosterAgent.new_pipeline
|
| 76 |
cmd = [
|
| 77 |
sys.executable, "-m", "PosterAgent.new_pipeline",
|
| 78 |
f'--poster_path={dst_pdf.relative_to(P2P_ROOT)}',
|
|
@@ -85,39 +67,28 @@ def run_paper2poster_content_build():
|
|
| 85 |
subprocess.run(cmd, cwd=str(P2P_ROOT), check=True)
|
| 86 |
print(" ✅ PosterAgent.new_pipeline finished.")
|
| 87 |
|
| 88 |
-
|
| 89 |
-
# 从 <4o_4o>_images_and_tables 推导前缀 <4o_4o>
|
| 90 |
-
tag_prefix = IMAGES_DIR_NAME.split("_images_and_tables")[0] # "<4o_4o>"
|
| 91 |
-
|
| 92 |
-
# 源路径
|
| 93 |
src_raw_content = P2P_ROOT / "contents" / f"{tag_prefix}_paper_raw_content.json"
|
| 94 |
src_tree_split = P2P_ROOT / "tree_splits" / f"{tag_prefix}_paper_tree_split_0.json"
|
| 95 |
src_images_json = P2P_ROOT / IMAGES_DIR_NAME / "paper_images.json"
|
| 96 |
|
| 97 |
-
# 目标(contents 下)
|
| 98 |
dst_contents_dir = PB_ROOT / "contents"
|
| 99 |
dst_raw_content = dst_contents_dir / "poster_content.json"
|
| 100 |
dst_tree_split = dst_contents_dir / "arrangement.json"
|
| 101 |
dst_fig_caption = dst_contents_dir / "figure_caption.json"
|
| 102 |
|
| 103 |
-
# 目标(包根,再各放一份,兼容不同读取方式)
|
| 104 |
dst_root_raw = PB_ROOT / "poster_content.json"
|
| 105 |
dst_root_tree = PB_ROOT / "arrangement.json"
|
| 106 |
dst_root_figcap = PB_ROOT / "figure_caption.json"
|
| 107 |
|
| 108 |
-
# 拷贝
|
| 109 |
safe_copy(src_raw_content, dst_raw_content)
|
| 110 |
safe_copy(src_tree_split, dst_tree_split)
|
| 111 |
safe_copy(src_images_json, dst_fig_caption)
|
| 112 |
-
# 兼容:在包根也放一份
|
| 113 |
safe_copy(src_raw_content, dst_root_raw)
|
| 114 |
safe_copy(src_tree_split, dst_root_tree)
|
| 115 |
safe_copy(src_images_json, dst_root_figcap)
|
| 116 |
|
| 117 |
-
print(" 📦 JSON copied & renamed
|
| 118 |
-
print(f" - {src_raw_content.relative_to(ROOT_DIR)} → posterbuilder/contents/poster_content.json (+ root)")
|
| 119 |
-
print(f" - {src_tree_split.relative_to(ROOT_DIR)} → posterbuilder/contents/arrangement.json (+ root)")
|
| 120 |
-
print(f" - {src_images_json.relative_to(ROOT_DIR)} → posterbuilder/contents/figure_caption.json (+ root)")
|
| 121 |
print(" ✅ Step 1.5 done.\n")
|
| 122 |
|
| 123 |
if __name__ == '__main__':
|
|
@@ -130,19 +101,22 @@ if __name__ == '__main__':
|
|
| 130 |
parser.add_argument('--if_tree_search', type=bool, default=True)
|
| 131 |
parser.add_argument('--beamer_templete_prompt', type=str, default=None)
|
| 132 |
parser.add_argument('--stage', type=str, default='["0"]')
|
| 133 |
-
parser.add_argument('--arxiv_url', type=str, default=None
|
|
|
|
|
|
|
| 134 |
|
| 135 |
args = parser.parse_args()
|
| 136 |
print("start")
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
output_dir = ROOT_DIR / "output"
|
| 142 |
if output_dir.exists():
|
| 143 |
print(f" 🧹 Clearing old output directory: {output_dir.relative_to(ROOT_DIR)}")
|
| 144 |
shutil.rmtree(output_dir)
|
| 145 |
-
|
| 146 |
(output_dir / "latex_proj").mkdir(parents=True, exist_ok=True)
|
| 147 |
(output_dir / "poster_latex_proj").mkdir(parents=True, exist_ok=True)
|
| 148 |
(output_dir / "slide_imgs").mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
import pdb
|
| 3 |
import json
|
|
|
|
| 15 |
|
| 16 |
from Paper2Video.src.slide_code_gen import latex_code_gen
|
| 17 |
from Paper2Video.src.wei_utils import get_agent_config
|
|
|
|
|
|
|
| 18 |
from posterbuilder import build_poster as build_poster
|
|
|
|
| 19 |
from posterbuilder.build_poster import IMAGES_DIR_NAME
|
| 20 |
|
|
|
|
| 21 |
ROOT_DIR = Path(__file__).resolve().parent
|
| 22 |
P2V_ASSETS = ROOT_DIR / "Paper2Video" / "assets" / "demo" / "latex_proj"
|
| 23 |
P2P_ROOT = ROOT_DIR / "Paper2Poster"
|
| 24 |
PB_ROOT = ROOT_DIR / "posterbuilder"
|
|
|
|
|
|
|
| 25 |
sys.path.append(str(P2P_ROOT))
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
def copy_folder(src_dir, dst_dir):
|
| 28 |
src_dir = Path(src_dir)
|
| 29 |
dst_dir = Path(dst_dir)
|
| 30 |
if not src_dir.exists():
|
| 31 |
raise FileNotFoundError(f"no such dir: {src_dir}")
|
|
|
|
| 32 |
if dst_dir.exists():
|
| 33 |
shutil.rmtree(dst_dir)
|
| 34 |
shutil.copytree(src_dir, dst_dir)
|
|
|
|
| 47 |
return [int(x) for x in s.split(',')]
|
| 48 |
|
| 49 |
def run_paper2poster_content_build():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
print("🧩 Step 1.5: Preparing Paper2Poster inputs & generating poster contents ...")
|
| 51 |
|
|
|
|
| 52 |
src_pdf = ROOT_DIR / "input" / "paper.pdf"
|
| 53 |
dst_pdf = P2P_ROOT / "input" / "paper" / "paper.pdf"
|
| 54 |
dst_pdf.parent.mkdir(parents=True, exist_ok=True)
|
| 55 |
safe_copy(src_pdf, dst_pdf)
|
| 56 |
print(f" 📄 Copied paper: {src_pdf.relative_to(ROOT_DIR)} → {dst_pdf.relative_to(ROOT_DIR)}")
|
| 57 |
|
|
|
|
| 58 |
cmd = [
|
| 59 |
sys.executable, "-m", "PosterAgent.new_pipeline",
|
| 60 |
f'--poster_path={dst_pdf.relative_to(P2P_ROOT)}',
|
|
|
|
| 67 |
subprocess.run(cmd, cwd=str(P2P_ROOT), check=True)
|
| 68 |
print(" ✅ PosterAgent.new_pipeline finished.")
|
| 69 |
|
| 70 |
+
tag_prefix = IMAGES_DIR_NAME.split("_images_and_tables")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
src_raw_content = P2P_ROOT / "contents" / f"{tag_prefix}_paper_raw_content.json"
|
| 72 |
src_tree_split = P2P_ROOT / "tree_splits" / f"{tag_prefix}_paper_tree_split_0.json"
|
| 73 |
src_images_json = P2P_ROOT / IMAGES_DIR_NAME / "paper_images.json"
|
| 74 |
|
|
|
|
| 75 |
dst_contents_dir = PB_ROOT / "contents"
|
| 76 |
dst_raw_content = dst_contents_dir / "poster_content.json"
|
| 77 |
dst_tree_split = dst_contents_dir / "arrangement.json"
|
| 78 |
dst_fig_caption = dst_contents_dir / "figure_caption.json"
|
| 79 |
|
|
|
|
| 80 |
dst_root_raw = PB_ROOT / "poster_content.json"
|
| 81 |
dst_root_tree = PB_ROOT / "arrangement.json"
|
| 82 |
dst_root_figcap = PB_ROOT / "figure_caption.json"
|
| 83 |
|
|
|
|
| 84 |
safe_copy(src_raw_content, dst_raw_content)
|
| 85 |
safe_copy(src_tree_split, dst_tree_split)
|
| 86 |
safe_copy(src_images_json, dst_fig_caption)
|
|
|
|
| 87 |
safe_copy(src_raw_content, dst_root_raw)
|
| 88 |
safe_copy(src_tree_split, dst_root_tree)
|
| 89 |
safe_copy(src_images_json, dst_root_figcap)
|
| 90 |
|
| 91 |
+
print(" 📦 JSON copied & renamed.")
|
|
|
|
|
|
|
|
|
|
| 92 |
print(" ✅ Step 1.5 done.\n")
|
| 93 |
|
| 94 |
if __name__ == '__main__':
|
|
|
|
| 101 |
parser.add_argument('--if_tree_search', type=bool, default=True)
|
| 102 |
parser.add_argument('--beamer_templete_prompt', type=str, default=None)
|
| 103 |
parser.add_argument('--stage', type=str, default='["0"]')
|
| 104 |
+
parser.add_argument('--arxiv_url', type=str, default=None)
|
| 105 |
+
parser.add_argument('--openai_key', type=str, required=True, help='Your OpenAI API key')
|
| 106 |
+
parser.add_argument('--gemini_key', type=str, required=True, help='Your Gemini API key')
|
| 107 |
|
| 108 |
args = parser.parse_args()
|
| 109 |
print("start")
|
| 110 |
|
| 111 |
+
# ✅ 使用传入的 key 设置环境变量
|
| 112 |
+
os.environ["OPENAI_API_KEY"] = args.openai_key
|
| 113 |
+
os.environ["GEMINI_API_KEY"] = args.gemini_key
|
| 114 |
+
|
| 115 |
+
# 清空 output
|
| 116 |
output_dir = ROOT_DIR / "output"
|
| 117 |
if output_dir.exists():
|
| 118 |
print(f" 🧹 Clearing old output directory: {output_dir.relative_to(ROOT_DIR)}")
|
| 119 |
shutil.rmtree(output_dir)
|
|
|
|
| 120 |
(output_dir / "latex_proj").mkdir(parents=True, exist_ok=True)
|
| 121 |
(output_dir / "poster_latex_proj").mkdir(parents=True, exist_ok=True)
|
| 122 |
(output_dir / "slide_imgs").mkdir(parents=True, exist_ok=True)
|