Fix HF Space preview + mask API key
Browse files- .gitignore +5 -0
- app.py +9 -2
- dataflow_agent/agentroles/cores/base_agent.py +10 -2
- gradio_app/app.py +4 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
*.log
|
| 5 |
+
outputs/
|
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
from gradio_app.app import PAGE_SETS, create_app
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def main() -> None:
|
|
@@ -16,9 +17,15 @@ def main() -> None:
|
|
| 16 |
page_names = PAGE_SETS["space"]
|
| 17 |
app = create_app(page_names)
|
| 18 |
app.queue()
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
main()
|
| 24 |
-
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
from gradio_app.app import PAGE_SETS, create_app
|
| 6 |
+
from gradio_app.utils.space_paths import get_persistent_outputs_root
|
| 7 |
|
| 8 |
|
| 9 |
def main() -> None:
|
|
|
|
| 17 |
page_names = PAGE_SETS["space"]
|
| 18 |
app = create_app(page_names)
|
| 19 |
app.queue()
|
| 20 |
+
# HF Space persistent storage is usually under /data, which is outside the
|
| 21 |
+
# repo root. Allow Gradio to serve generated images/PDFs from that directory.
|
| 22 |
+
app.launch(
|
| 23 |
+
server_name=server_name,
|
| 24 |
+
server_port=port,
|
| 25 |
+
share=False,
|
| 26 |
+
allowed_paths=[str(get_persistent_outputs_root())],
|
| 27 |
+
)
|
| 28 |
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
main()
|
|
|
dataflow_agent/agentroles/cores/base_agent.py
CHANGED
|
@@ -72,6 +72,14 @@ PROJDIR = get_project_root()
|
|
| 72 |
log = get_logger(__name__)
|
| 73 |
"""模块日志记录器"""
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# =============================================================================
|
| 76 |
# 类型定义
|
| 77 |
# =============================================================================
|
|
@@ -557,7 +565,7 @@ class BaseAgent(ABC):
|
|
| 557 |
|
| 558 |
log.info(f"[create_llm:]创建LLM实例,温度: {self.temperature}, "
|
| 559 |
f"最大token: {self.max_tokens}, 模型: {actual_model}, "
|
| 560 |
-
f"接口URL: {actual_url}, API Key: {state.request.api_key}")
|
| 561 |
|
| 562 |
# 创建 LLM 实例
|
| 563 |
llm = ChatOpenAI(
|
|
@@ -1535,4 +1543,4 @@ class BaseAgent(ABC):
|
|
| 1535 |
log.info(f"parsed 内容: {parsed}")
|
| 1536 |
log.info(f"additional_kwargs 内容: {response.additional_kwargs}")
|
| 1537 |
|
| 1538 |
-
return parsed
|
|
|
|
| 72 |
log = get_logger(__name__)
|
| 73 |
"""模块日志记录器"""
|
| 74 |
|
| 75 |
+
def _mask_secret(value: str | None) -> str:
|
| 76 |
+
if not value:
|
| 77 |
+
return ""
|
| 78 |
+
s = str(value)
|
| 79 |
+
if len(s) <= 8:
|
| 80 |
+
return "*" * len(s)
|
| 81 |
+
return f"{s[:4]}...{s[-4:]}"
|
| 82 |
+
|
| 83 |
# =============================================================================
|
| 84 |
# 类型定义
|
| 85 |
# =============================================================================
|
|
|
|
| 565 |
|
| 566 |
log.info(f"[create_llm:]创建LLM实例,温度: {self.temperature}, "
|
| 567 |
f"最大token: {self.max_tokens}, 模型: {actual_model}, "
|
| 568 |
+
f"接口URL: {actual_url}, API Key: {_mask_secret(state.request.api_key)}")
|
| 569 |
|
| 570 |
# 创建 LLM 实例
|
| 571 |
llm = ChatOpenAI(
|
|
|
|
| 1543 |
log.info(f"parsed 内容: {parsed}")
|
| 1544 |
log.info(f"additional_kwargs 内容: {response.additional_kwargs}")
|
| 1545 |
|
| 1546 |
+
return parsed
|
gradio_app/app.py
CHANGED
|
@@ -38,6 +38,7 @@ def _ensure_httpx_proxy_compat() -> None:
|
|
| 38 |
_ensure_httpx_proxy_compat()
|
| 39 |
|
| 40 |
import gradio as gr
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
# 标签显示名称映射,如果需要自定义页面名称
|
|
@@ -199,4 +200,7 @@ if __name__ == "__main__":
|
|
| 199 |
server_name=server_name,
|
| 200 |
server_port=port,
|
| 201 |
share=False,
|
|
|
|
|
|
|
|
|
|
| 202 |
)
|
|
|
|
| 38 |
_ensure_httpx_proxy_compat()
|
| 39 |
|
| 40 |
import gradio as gr
|
| 41 |
+
from gradio_app.utils.space_paths import get_persistent_outputs_root
|
| 42 |
|
| 43 |
|
| 44 |
# 标签显示名称映射,如果需要自定义页面名称
|
|
|
|
| 200 |
server_name=server_name,
|
| 201 |
server_port=port,
|
| 202 |
share=False,
|
| 203 |
+
# Outputs may be configured to go outside repo root (e.g. HF /data).
|
| 204 |
+
# Allow Gradio to serve generated images/PDFs from the outputs root.
|
| 205 |
+
allowed_paths=[str(get_persistent_outputs_root())],
|
| 206 |
)
|
requirements.txt
CHANGED
|
@@ -11,6 +11,8 @@ pydantic
|
|
| 11 |
pyyaml
|
| 12 |
cloudpickle
|
| 13 |
|
|
|
|
|
|
|
| 14 |
openai
|
| 15 |
tiktoken
|
| 16 |
langgraph==0.6.7
|
|
|
|
| 11 |
pyyaml
|
| 12 |
cloudpickle
|
| 13 |
|
| 14 |
+
beautifulsoup4
|
| 15 |
+
|
| 16 |
openai
|
| 17 |
tiktoken
|
| 18 |
langgraph==0.6.7
|