-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
135 lines (109 loc) · 3.51 KB
/
Copy pathrun.py
File metadata and controls
135 lines (109 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
"""
论文身份卡自动提取系统 - 统一命令行入口
==========================================
使用方法:
python run.py extract # P0: 提取论文信息
python run.py rescore # P1: 场景重算评分
python run.py cluster # P2: 聚类分析
python run.py api # 启动 FastAPI 后端服务
python run.py full # 运行完整流水线 (extract → rescore → cluster)
示例:
python run.py extract # 交互式提取
python run.py rescore # 场景重算
python run.py api # 启动后端API
python run.py full # 完整流水线
"""
import sys
import subprocess
from pathlib import Path
# 项目根目录
ROOT_DIR = Path(__file__).parent.resolve()
SRC_DIR = ROOT_DIR / "src"
API_DIR = ROOT_DIR / "api"
FRONTEND_DIR = ROOT_DIR / "frontend"
def run_extract():
"""运行 P0 提取脚本"""
print("=" * 60)
print(" 📄 P0: 论文信息提取")
print("=" * 60)
subprocess.run([sys.executable, "-m", "src.extraction"], cwd=ROOT_DIR)
def run_rescore():
"""运行 P1 场景重算脚本"""
print("=" * 60)
print(" 🎯 P1: 场景重算评分")
print("=" * 60)
subprocess.run([sys.executable, "-m", "src.rescoring"], cwd=ROOT_DIR)
def run_cluster():
"""运行 P2 聚类分析脚本"""
print("=" * 60)
print(" 🔗 P2: 聚类分析")
print("=" * 60)
subprocess.run([sys.executable, "-m", "src.clustering"], cwd=ROOT_DIR)
def run_api():
"""启动 FastAPI 后端服务"""
print("=" * 60)
print(" 🚀 启动 FastAPI 后端服务")
print("=" * 60)
print(f" 📁 API 目录: {API_DIR}")
print(" 🌐 API 地址: http://localhost:8000")
print(" 📖 API 文档: http://localhost:8000/api/v1/docs")
print("=" * 60)
subprocess.run([
sys.executable, "-m", "uvicorn",
"api.main:app",
"--reload",
"--host", "0.0.0.0",
"--port", "8000"
], cwd=ROOT_DIR)
def run_full_pipeline():
"""运行完整流水线"""
print("=" * 60)
print(" 🔄 运行完整流水线")
print("=" * 60)
steps = [
("P0: 提取", run_extract),
("P1: 重算", run_rescore),
("P2: 聚类", run_cluster),
]
for name, func in steps:
print(f"\n>>> {name}")
func()
print("\n" + "=" * 60)
print(" ✅ 流水线完成!")
print("=" * 60)
def show_help():
"""显示帮助信息"""
print(__doc__)
print("可用命令:")
print(" extract - P0: 提取论文信息")
print(" rescore - P1: 场景重算评分")
print(" cluster - P2: 聚类分析")
print(" api - 启动 FastAPI 后端服务")
print(" full - 运行完整流水线")
print(" help - 显示此帮助信息")
def main():
if len(sys.argv) < 2:
show_help()
return
command = sys.argv[1].lower()
commands = {
"extract": run_extract,
"rescore": run_rescore,
"cluster": run_cluster,
"api": run_api,
"server": run_api,
"full": run_full_pipeline,
"all": run_full_pipeline,
"help": show_help,
"-h": show_help,
"--help": show_help,
}
if command in commands:
commands[command]()
else:
print(f"❌ 未知命令: {command}")
print("运行 'python run.py help' 查看可用命令")
sys.exit(1)
if __name__ == "__main__":
main()