diff --git a/bigwork/final_models/crisis_index_model.pkl b/bigwork/final_models/crisis_index_model.pkl index 85528b5..d330074 100644 Binary files a/bigwork/final_models/crisis_index_model.pkl and b/bigwork/final_models/crisis_index_model.pkl differ diff --git a/bigwork/final_models/trend_analysis_model.pkl b/bigwork/final_models/trend_analysis_model.pkl index 2509e8a..89331d5 100644 Binary files a/bigwork/final_models/trend_analysis_model.pkl and b/bigwork/final_models/trend_analysis_model.pkl differ diff --git a/bigwork/src/deepseek_integrator.py b/bigwork/src/deepseek_integrator.py index b5598ca..63409ce 100644 --- a/bigwork/src/deepseek_integrator.py +++ b/bigwork/src/deepseek_integrator.py @@ -5,6 +5,7 @@ import requests from dotenv import load_dotenv import pandas as pd import numpy as np +from pathlib import Path class DeepSeekIntegrator: def __init__(self, api_key=None): @@ -13,7 +14,10 @@ class DeepSeekIntegrator: # 如果没有提供API密钥,尝试从环境变量加载 if not api_key: - load_dotenv() + # 获取项目根目录的.env文件路径 + project_root = Path(__file__).parent.parent + env_path = project_root / ".env" + load_dotenv(dotenv_path=env_path) self.api_key = os.getenv("DEEPSEEK_API_KEY") # 模拟数据 - 实际使用时替换为真实API调用 @@ -60,7 +64,9 @@ class DeepSeekIntegrator: def _call_api(self, prompt, max_tokens=1000, temperature=0.7): """调用DeepSeek API""" # 重新加载环境变量,确保使用最新的API密钥 - load_dotenv() + project_root = Path(__file__).parent.parent + env_path = project_root / ".env" + load_dotenv(dotenv_path=env_path) current_api_key = os.getenv("DEEPSEEK_API_KEY") # 如果实例化时没有提供API密钥,使用当前环境变量中的值 @@ -293,4 +299,4 @@ if __name__ == "__main__": print("\n=== 测试传播预测 ===") initial_impact = "目前已有500名乘客在社交媒体上表达不满,相关话题讨论量达到1000条" propagation = integrator.predict_propagation(current_event, initial_impact) - print(propagation) + print(propagation) \ No newline at end of file