Fix PDF export + mask image API key
Browse files
dataflow_agent/toolkits/imtool/req_img.py
CHANGED
|
@@ -19,6 +19,17 @@ class Provider(str, Enum):
|
|
| 19 |
_B64_RE = re.compile(r"[A-Za-z0-9+/=]+") # 匹配 Base64 字符
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def detect_provider(api_url: str) -> Provider:
|
| 23 |
"""
|
| 24 |
根据 api_url 粗略识别服务商
|
|
@@ -823,7 +834,9 @@ async def generate_or_edit_and_save_image_async(
|
|
| 823 |
timeout_map = {"1K": 180, "2K": 300, "4K": 360}
|
| 824 |
timeout = timeout_map.get(resolution, 300)
|
| 825 |
|
| 826 |
-
log.info(
|
|
|
|
|
|
|
| 827 |
# 根据模型类型选择不同的API
|
| 828 |
if _is_dalle_model(model):
|
| 829 |
if use_edit:
|
|
|
|
| 19 |
_B64_RE = re.compile(r"[A-Za-z0-9+/=]+") # 匹配 Base64 字符
|
| 20 |
|
| 21 |
|
| 22 |
+
def _mask_secret(value: str, keep_start: int = 4, keep_end: int = 4) -> str:
|
| 23 |
+
if value is None:
|
| 24 |
+
return ""
|
| 25 |
+
s = str(value)
|
| 26 |
+
if not s:
|
| 27 |
+
return ""
|
| 28 |
+
if len(s) <= keep_start + keep_end:
|
| 29 |
+
return "*" * len(s)
|
| 30 |
+
return f"{s[:keep_start]}...{s[-keep_end:]}"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
def detect_provider(api_url: str) -> Provider:
|
| 34 |
"""
|
| 35 |
根据 api_url 粗略识别服务商
|
|
|
|
| 834 |
timeout_map = {"1K": 180, "2K": 300, "4K": 360}
|
| 835 |
timeout = timeout_map.get(resolution, 300)
|
| 836 |
|
| 837 |
+
log.info(
|
| 838 |
+
f"aspect_ratio: {aspect_ratio} \n resolution: {resolution} \n use_edit: {use_edit} \n model: {model} \n api_url: {api_url} \n timeout: {timeout} \n api_key: {_mask_secret(api_key)}"
|
| 839 |
+
)
|
| 840 |
# 根据模型类型选择不同的API
|
| 841 |
if _is_dalle_model(model):
|
| 842 |
if use_edit:
|
dataflow_agent/workflow/wf_paper2ppt_parallel.py
CHANGED
|
@@ -467,7 +467,6 @@ def create_paper2ppt_parallel_graph() -> GenericGraphBuilder: # noqa: N802
|
|
| 467 |
state.generated_pages.append("")
|
| 468 |
|
| 469 |
state.pagecontent = new_pagecontent
|
| 470 |
-
state.gen_down = True
|
| 471 |
return state
|
| 472 |
|
| 473 |
async def edit_single_page(state: Paper2FigureState) -> Paper2FigureState:
|
|
|
|
| 467 |
state.generated_pages.append("")
|
| 468 |
|
| 469 |
state.pagecontent = new_pagecontent
|
|
|
|
| 470 |
return state
|
| 471 |
|
| 472 |
async def edit_single_page(state: Paper2FigureState) -> Paper2FigureState:
|
gradio_app/pages/paper2ppt.py
CHANGED
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
| 6 |
-
from typing import Any, Dict, List, Tuple
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
|
|
@@ -38,11 +38,11 @@ def _list_generated_pages(run_dir: str) -> list[str]:
|
|
| 38 |
return [str(p.resolve()) for p in sorted(img_dir.glob("page_*.png"))]
|
| 39 |
|
| 40 |
|
| 41 |
-
def _pdf_path(run_dir: str) -> str:
|
| 42 |
if not run_dir:
|
| 43 |
-
return
|
| 44 |
p = Path(run_dir) / "paper2ppt.pdf"
|
| 45 |
-
return str(p.resolve()) if p.exists() else
|
| 46 |
|
| 47 |
|
| 48 |
async def _run_pagecontent(
|
|
@@ -108,7 +108,7 @@ async def _run_generate(
|
|
| 108 |
gen_fig_model: str,
|
| 109 |
style: str,
|
| 110 |
aspect_ratio: str,
|
| 111 |
-
) -> Tuple[list[str], str]:
|
| 112 |
if not run_dir:
|
| 113 |
raise gr.Error("请先生成 pagecontent。")
|
| 114 |
if not (gen_fig_model or "").strip():
|
|
@@ -189,7 +189,7 @@ async def _run_edit_one(
|
|
| 189 |
return _list_generated_pages(run_dir)
|
| 190 |
|
| 191 |
|
| 192 |
-
async def _run_export(run_dir: str, language: str, chat_api_url: str, api_key: str, llm_model: str, gen_fig_model: str) -> str:
|
| 193 |
if not run_dir:
|
| 194 |
raise gr.Error("请先生成一次 PPT(产生 ppt_pages/page_*.png)。")
|
| 195 |
os.environ["DF_API_KEY"] = api_key
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
| 6 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
|
|
|
|
| 38 |
return [str(p.resolve()) for p in sorted(img_dir.glob("page_*.png"))]
|
| 39 |
|
| 40 |
|
| 41 |
+
def _pdf_path(run_dir: str) -> Optional[str]:
|
| 42 |
if not run_dir:
|
| 43 |
+
return None
|
| 44 |
p = Path(run_dir) / "paper2ppt.pdf"
|
| 45 |
+
return str(p.resolve()) if p.exists() else None
|
| 46 |
|
| 47 |
|
| 48 |
async def _run_pagecontent(
|
|
|
|
| 108 |
gen_fig_model: str,
|
| 109 |
style: str,
|
| 110 |
aspect_ratio: str,
|
| 111 |
+
) -> Tuple[list[str], Optional[str]]:
|
| 112 |
if not run_dir:
|
| 113 |
raise gr.Error("请先生成 pagecontent。")
|
| 114 |
if not (gen_fig_model or "").strip():
|
|
|
|
| 189 |
return _list_generated_pages(run_dir)
|
| 190 |
|
| 191 |
|
| 192 |
+
async def _run_export(run_dir: str, language: str, chat_api_url: str, api_key: str, llm_model: str, gen_fig_model: str) -> Optional[str]:
|
| 193 |
if not run_dir:
|
| 194 |
raise gr.Error("请先生成一次 PPT(产生 ppt_pages/page_*.png)。")
|
| 195 |
os.environ["DF_API_KEY"] = api_key
|
gradio_app/pages/paper2video.py
CHANGED
|
@@ -103,7 +103,7 @@ def create_paper2video() -> gr.Blocks:
|
|
| 103 |
str(target_img_path) if image_path else None
|
| 104 |
)
|
| 105 |
# 提取结果
|
| 106 |
-
ppt_path = result.get("ppt_path"
|
| 107 |
|
| 108 |
# 构建日志信息
|
| 109 |
if ppt_path and Path(ppt_path).exists():
|
|
@@ -111,12 +111,12 @@ def create_paper2video() -> gr.Blocks:
|
|
| 111 |
return str(ppt_path)
|
| 112 |
else:
|
| 113 |
log.error("未能生成 PPT 文件。")
|
| 114 |
-
return
|
| 115 |
except Exception as e:
|
| 116 |
import traceback
|
| 117 |
error_msg = f"执行失败:\n{traceback.format_exc()}"
|
| 118 |
print(f"错误: {error_msg}")
|
| 119 |
-
return
|
| 120 |
|
| 121 |
|
| 122 |
gen_btn.click(
|
|
@@ -201,4 +201,4 @@ async def run_paper2video_pipeline(
|
|
| 201 |
log.warning(f"提取pdf的ppt失败: {e}")
|
| 202 |
result["ppt_path"] = []
|
| 203 |
|
| 204 |
-
return result
|
|
|
|
| 103 |
str(target_img_path) if image_path else None
|
| 104 |
)
|
| 105 |
# 提取结果
|
| 106 |
+
ppt_path = result.get("ppt_path")
|
| 107 |
|
| 108 |
# 构建日志信息
|
| 109 |
if ppt_path and Path(ppt_path).exists():
|
|
|
|
| 111 |
return str(ppt_path)
|
| 112 |
else:
|
| 113 |
log.error("未能生成 PPT 文件。")
|
| 114 |
+
return None
|
| 115 |
except Exception as e:
|
| 116 |
import traceback
|
| 117 |
error_msg = f"执行失败:\n{traceback.format_exc()}"
|
| 118 |
print(f"错误: {error_msg}")
|
| 119 |
+
return None
|
| 120 |
|
| 121 |
|
| 122 |
gen_btn.click(
|
|
|
|
| 201 |
log.warning(f"提取pdf的ppt失败: {e}")
|
| 202 |
result["ppt_path"] = []
|
| 203 |
|
| 204 |
+
return result
|
gradio_app/pages/ppt2polish.py
CHANGED
|
@@ -4,7 +4,7 @@ import json
|
|
| 4 |
import os
|
| 5 |
import shutil
|
| 6 |
from pathlib import Path
|
| 7 |
-
from typing import Tuple
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
|
|
@@ -24,11 +24,11 @@ def _list_generated_pages(run_dir: str) -> list[str]:
|
|
| 24 |
return [str(p.resolve()) for p in sorted(img_dir.glob("page_*.png"))]
|
| 25 |
|
| 26 |
|
| 27 |
-
def _pdf_path(run_dir: str) -> str:
|
| 28 |
if not run_dir:
|
| 29 |
-
return
|
| 30 |
p = Path(run_dir) / "paper2ppt.pdf"
|
| 31 |
-
return str(p.resolve()) if p.exists() else
|
| 32 |
|
| 33 |
|
| 34 |
def _safe_json_loads(s: str) -> list[dict]:
|
|
@@ -108,7 +108,7 @@ async def _run_polish_all(
|
|
| 108 |
gen_fig_model: str,
|
| 109 |
style: str,
|
| 110 |
aspect_ratio: str,
|
| 111 |
-
) -> Tuple[list[str], str]:
|
| 112 |
if not run_dir:
|
| 113 |
raise gr.Error("请先生成 pagecontent。")
|
| 114 |
if not (gen_fig_model or "").strip():
|
|
@@ -188,7 +188,7 @@ async def _run_edit_one(
|
|
| 188 |
return _list_generated_pages(run_dir)
|
| 189 |
|
| 190 |
|
| 191 |
-
async def _run_export(run_dir: str, language: str, chat_api_url: str, api_key: str, llm_model: str, gen_fig_model: str) -> str:
|
| 192 |
if not run_dir:
|
| 193 |
raise gr.Error("请先生成一次 polish(产生 ppt_pages/page_*.png)。")
|
| 194 |
os.environ["DF_API_KEY"] = api_key
|
|
|
|
| 4 |
import os
|
| 5 |
import shutil
|
| 6 |
from pathlib import Path
|
| 7 |
+
from typing import Optional, Tuple
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
|
|
|
|
| 24 |
return [str(p.resolve()) for p in sorted(img_dir.glob("page_*.png"))]
|
| 25 |
|
| 26 |
|
| 27 |
+
def _pdf_path(run_dir: str) -> Optional[str]:
|
| 28 |
if not run_dir:
|
| 29 |
+
return None
|
| 30 |
p = Path(run_dir) / "paper2ppt.pdf"
|
| 31 |
+
return str(p.resolve()) if p.exists() else None
|
| 32 |
|
| 33 |
|
| 34 |
def _safe_json_loads(s: str) -> list[dict]:
|
|
|
|
| 108 |
gen_fig_model: str,
|
| 109 |
style: str,
|
| 110 |
aspect_ratio: str,
|
| 111 |
+
) -> Tuple[list[str], Optional[str]]:
|
| 112 |
if not run_dir:
|
| 113 |
raise gr.Error("请先生成 pagecontent。")
|
| 114 |
if not (gen_fig_model or "").strip():
|
|
|
|
| 188 |
return _list_generated_pages(run_dir)
|
| 189 |
|
| 190 |
|
| 191 |
+
async def _run_export(run_dir: str, language: str, chat_api_url: str, api_key: str, llm_model: str, gen_fig_model: str) -> Optional[str]:
|
| 192 |
if not run_dir:
|
| 193 |
raise gr.Error("请先生成一次 polish(产生 ppt_pages/page_*.png)。")
|
| 194 |
os.environ["DF_API_KEY"] = api_key
|