You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
import json |
|
import requests |
|
import os |
|
|
|
# 配置文件路径 |
|
test_file_path = r"D:\workstation\chinese-roberta-wwm-ext\model-train-eval-NN\AI标注\test.json" |
|
output_dir = r"D:\workstation\chinese-roberta-wwm-ext\model-train-eval-NN\AI标注\test01" |
|
|
|
# 确保输出目录存在 |
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
# 读取测试数据 |
|
with open(test_file_path, 'r', encoding='utf-8') as f: |
|
test_data = json.load(f) |
|
|
|
print(f"📁 加载测试数据: {len(test_data)} 条记录") |
|
|
|
# 服务地址 |
|
url = "http://localhost:8888/segment_batch_simple" |
|
|
|
# 准备请求数据 - 直接使用原始格式 |
|
broadcasts = test_data |
|
|
|
print(f"🚀 开始调用双路径边界分类器批量分段接口...") |
|
|
|
# 发送请求 |
|
try: |
|
response = requests.post(url, json=broadcasts) |
|
|
|
if response.status_code == 200: |
|
result = response.json() |
|
print("✅ 批量分段成功!") |
|
print(f"模型: {result['model']}") |
|
print(f"总计: {result['total']}") |
|
print(f"成功: {result['success']}") |
|
print(f"失败: {result['failed']}") |
|
print(f"处理时间: {result['processing_time']}秒") |
|
|
|
print("\n📝 分段结果:") |
|
print("=" * 80) |
|
|
|
for broadcast_id, segments in result['results'].items(): |
|
print(f"\n📻 {broadcast_id}:") |
|
|
|
if 'error' in segments: |
|
print(f"❌ 错误: {segments['error']}") |
|
else: |
|
for para_key, para_content in segments.items(): |
|
print(f" {para_key}: {para_content}") |
|
|
|
# 保存结果到文件 |
|
output_file = os.path.join(output_dir, "batch_segment_results.json") |
|
with open(output_file, 'w', encoding='utf-8') as f: |
|
json.dump(result, f, ensure_ascii=False, indent=2) |
|
|
|
print(f"\n💾 结果已保存到: {output_file}") |
|
|
|
else: |
|
print(f"❌ 请求失败: HTTP {response.status_code}") |
|
print(response.text) |
|
|
|
except requests.exceptions.ConnectionError: |
|
print("❌ 连接失败,请确保双路径边界分类器服务正在运行") |
|
print(" 启动命令: python simplified_dual_path_boundary_classifier_api.py") |
|
print(" 服务地址: http://localhost:8888") |
|
except Exception as e: |
|
print(f"❌ 调用失败: {e}") |