Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
| 5 |
import torch
|
| 6 |
import os
|
| 7 |
from typing import List, Optional
|
|
|
|
| 8 |
|
| 9 |
# 1. 初始化FastAPI应用
|
| 10 |
app = FastAPI(
|
|
@@ -53,12 +54,16 @@ class DocumentScore(BaseModel):
|
|
| 53 |
|
| 54 |
class RerankResponse(BaseModel):
|
| 55 |
"""重排序响应模型"""
|
|
|
|
|
|
|
|
|
|
| 56 |
request_id: str # 请求唯一标识(便于排查问题)
|
| 57 |
query: str # 回显请求的查询
|
| 58 |
top_k: int # 回显请求的Top K
|
| 59 |
results: List[DocumentScore] # 排序结果列表
|
| 60 |
model: str = "cross-encoder/ms-marco-MiniLM-L-6-v2" # 使用的模型名称
|
| 61 |
-
timestamp: str =
|
|
|
|
| 62 |
|
| 63 |
# 4. 加载Cross-Encoder模型(全局初始化,避免重复加载)
|
| 64 |
class CrossEncoderLoader:
|
|
|
|
| 5 |
import torch
|
| 6 |
import os
|
| 7 |
from typing import List, Optional
|
| 8 |
+
from datetime import datetime # 需在文件开头导入
|
| 9 |
|
| 10 |
# 1. 初始化FastAPI应用
|
| 11 |
app = FastAPI(
|
|
|
|
| 54 |
|
| 55 |
class RerankResponse(BaseModel):
|
| 56 |
"""重排序响应模型"""
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
request_id: str # 请求唯一标识(便于排查问题)
|
| 61 |
query: str # 回显请求的查询
|
| 62 |
top_k: int # 回显请求的Top K
|
| 63 |
results: List[DocumentScore] # 排序结果列表
|
| 64 |
model: str = "cross-encoder/ms-marco-MiniLM-L-6-v2" # 使用的模型名称
|
| 65 |
+
timestamp: str = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] # 用标准库生成时间戳
|
| 66 |
+
|
| 67 |
|
| 68 |
# 4. 加载Cross-Encoder模型(全局初始化,避免重复加载)
|
| 69 |
class CrossEncoderLoader:
|