Spaces:
Running
Running
Update gen_dag.py
Browse files- gen_dag.py +6 -14
gen_dag.py
CHANGED
|
@@ -6,23 +6,14 @@ 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 |
-
#
|
| 26 |
config = {
|
| 27 |
"model_settings": {
|
| 28 |
"generation_model": generation_model
|
|
@@ -31,16 +22,17 @@ def load_config():
|
|
| 31 |
"root_folder": user_root_folder
|
| 32 |
},
|
| 33 |
"api_keys": {
|
| 34 |
-
"gemini_api_key": api_key
|
| 35 |
-
|
| 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 |
|
|
|
|
| 6 |
|
| 7 |
# ============= 从环境变量动态生成配置 ===============
|
| 8 |
def load_config():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
base_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
| 10 |
user_root_folder = os.environ.get("USER_OUTPUT_DIR", os.path.join(base_dir, "mineru_outputs"))
|
| 11 |
|
|
|
|
| 12 |
api_key = os.environ.get("GEMINI_API_KEY", "")
|
| 13 |
api_base_url = os.environ.get("GEMINI_API_BASE_URL", "")
|
|
|
|
|
|
|
| 14 |
generation_model = os.environ.get("GENERATION_MODEL", "gemini-3-pro-preview")
|
| 15 |
|
| 16 |
+
# ✅ 修正字典结构:把 api_base_url 移回到外层,和原版 config.yaml 保持绝对一致
|
| 17 |
config = {
|
| 18 |
"model_settings": {
|
| 19 |
"generation_model": generation_model
|
|
|
|
| 22 |
"root_folder": user_root_folder
|
| 23 |
},
|
| 24 |
"api_keys": {
|
| 25 |
+
"gemini_api_key": api_key
|
| 26 |
+
},
|
| 27 |
+
"api_base_url": api_base_url # <--- ✅ 放在这里才对!
|
| 28 |
}
|
| 29 |
|
|
|
|
| 30 |
if api_key:
|
| 31 |
os.environ["GEMINI_API_KEY"] = api_key
|
| 32 |
+
os.environ["GOOGLE_API_KEY"] = api_key
|
| 33 |
if api_base_url:
|
| 34 |
os.environ["GEMINI_API_BASE_URL"] = api_base_url
|
| 35 |
+
os.environ["GOOGLE_API_BASE"] = api_base_url
|
| 36 |
|
| 37 |
return config
|
| 38 |
|