Compare commits
No commits in common. "a9c049132b867bb317a42b720835dc2d8ff6b238" and "ef08f243a3be20e999cddd1e2e70d9d15db1983a" have entirely different histories.
a9c049132b
...
ef08f243a3
284808
data/creditcard.csv
284808
data/creditcard.csv
File diff suppressed because it is too large
Load Diff
@ -239,52 +239,27 @@ def create_agent(model_dir: str = "models", model_name: str = "random_forest") -
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import subprocess
|
agent = create_agent()
|
||||||
import webbrowser
|
|
||||||
import time
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
print("=== 信用卡欺诈检测系统 ===")
|
print("=== 可用工具 ===")
|
||||||
print("\n正在启动Web界面...\n")
|
for tool in agent.list_tools():
|
||||||
|
print(f"- {tool['name']}: {tool['description']}")
|
||||||
|
|
||||||
streamlit_app_path = Path(__file__).parent / "streamlit_app.py"
|
test_transaction = [
|
||||||
|
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
|
||||||
|
]
|
||||||
|
|
||||||
if not streamlit_app_path.exists():
|
result = agent.process_transaction(test_transaction)
|
||||||
print(f"错误: 找不到streamlit_app.py文件: {streamlit_app_path}")
|
print("\n=== 决策结果 ===")
|
||||||
exit(1)
|
print(f"预测类别: {result.evaluation.class_name}")
|
||||||
|
print(f"欺诈概率: {result.evaluation.fraud_probability:.4f}")
|
||||||
process = subprocess.Popen(
|
print(f"置信度: {result.evaluation.confidence}")
|
||||||
["streamlit", "run", str(streamlit_app_path), "--server.headless", "true"],
|
print(f"关键特征数量: {len(result.explanation.key_features)}")
|
||||||
stdout=subprocess.PIPE,
|
print(f"行动建议数量: {len(result.action_plan.actions)}")
|
||||||
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