Compare commits
2 Commits
ef08f243a3
...
a9c049132b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9c049132b | ||
|
|
317be70b11 |
284808
data/creditcard.csv
Normal file
284808
data/creditcard.csv
Normal file
File diff suppressed because it is too large
Load Diff
@ -239,27 +239,52 @@ def create_agent(model_dir: str = "models", model_name: str = "random_forest") -
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
agent = create_agent()
|
import subprocess
|
||||||
|
import webbrowser
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
print("=== 可用工具 ===")
|
print("=== 信用卡欺诈检测系统 ===")
|
||||||
for tool in agent.list_tools():
|
print("\n正在启动Web界面...\n")
|
||||||
print(f"- {tool['name']}: {tool['description']}")
|
|
||||||
|
|
||||||
test_transaction = [
|
streamlit_app_path = Path(__file__).parent / "streamlit_app.py"
|
||||||
0, -1.3598071336738, -0.0727811733098497, 2.53634673796914, 1.37815522427443,
|
|
||||||
-0.338320769942518, 0.462387777762292, 0.239598554061257, 0.0986979012610507,
|
|
||||||
0.363786969611213, 0.0907941719789316, -0.551599533260813, -0.617800855762348,
|
|
||||||
-0.991389847235408, -0.311169353699879, 1.46817697209427, -0.470400525259478,
|
|
||||||
0.207971241929242, 0.0257905801985591, 0.403992960255733, 0.251412098239705,
|
|
||||||
-0.018306777944153, 0.277837575558899, -0.110473910188767, 0.0669280749146731,
|
|
||||||
0.128539358273528, -0.189114843888824, 0.133558376740387, -0.0210530534538215,
|
|
||||||
149.62
|
|
||||||
]
|
|
||||||
|
|
||||||
result = agent.process_transaction(test_transaction)
|
if not streamlit_app_path.exists():
|
||||||
print("\n=== 决策结果 ===")
|
print(f"错误: 找不到streamlit_app.py文件: {streamlit_app_path}")
|
||||||
print(f"预测类别: {result.evaluation.class_name}")
|
exit(1)
|
||||||
print(f"欺诈概率: {result.evaluation.fraud_probability:.4f}")
|
|
||||||
print(f"置信度: {result.evaluation.confidence}")
|
process = subprocess.Popen(
|
||||||
print(f"关键特征数量: {len(result.explanation.key_features)}")
|
["streamlit", "run", str(streamlit_app_path), "--server.headless", "true"],
|
||||||
print(f"行动建议数量: {len(result.action_plan.actions)}")
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
print("✓ Web服务正在启动...")
|
||||||
|
print("✓ 请等待几秒钟,服务将自动在浏览器中打开\n")
|
||||||
|
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
print("=" * 60)
|
||||||
|
print("🌐 信用卡欺诈检测系统Web界面")
|
||||||
|
print("=" * 60)
|
||||||
|
print("\n📋 访问信息:")
|
||||||
|
print(" 本地访问: http://localhost:8501")
|
||||||
|
print(" 网络访问: http://0.0.0.0:8501")
|
||||||
|
print("\n💡 提示:")
|
||||||
|
print(" - 如果浏览器没有自动打开,请手动访问上述链接")
|
||||||
|
print(" - 按 Ctrl+C 可以停止服务")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
webbrowser.open("http://localhost:8501")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n⚠️ 无法自动打开浏览器: {e}")
|
||||||
|
print(" 请手动访问: http://localhost:8501")
|
||||||
|
|
||||||
|
try:
|
||||||
|
process.wait()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n\n正在停止服务...")
|
||||||
|
process.terminate()
|
||||||
|
print("✓ 服务已停止")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user