Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,26 @@
|
|
| 1 |
-
|
| 2 |
from fastapi.security import APIKeyQuery, APIKeyHeader
|
| 3 |
-
from pydantic import BaseModel
|
| 4 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 5 |
-
import torch
|
| 6 |
-
import os
|
| 7 |
from typing import List, Optional
|
| 8 |
from datetime import datetime # 需在文件开头导入
|
| 9 |
-
from fastapi.responses import MarkdownResponse
|
| 10 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
|
| 12 |
class CrossEncoderWrapper:
|
| 13 |
def __init__(self):
|
|
|
|
| 1 |
+
|
| 2 |
from fastapi.security import APIKeyQuery, APIKeyHeader
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from typing import List, Optional
|
| 4 |
from datetime import datetime # 需在文件开头导入
|
|
|
|
| 5 |
import os
|
| 6 |
+
import uuid
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
from fastapi import FastAPI, HTTPException, Depends
|
| 9 |
+
from fastapi.responses import MarkdownResponse # 确保导入这行
|
| 10 |
+
from pydantic import BaseModel
|
| 11 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 12 |
+
import torch
|
| 13 |
+
|
| 14 |
+
# 【双重保障】设置 Hugging Face 缓存目录(与 Dockerfile 一致)
|
| 15 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
|
| 16 |
+
os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface_cache"
|
| 17 |
+
|
| 18 |
+
# 初始化 FastAPI 应用
|
| 19 |
+
app = FastAPI(title="Cross-Encoder 重排序 API(兼容 GPT 格式)")
|
| 20 |
+
|
| 21 |
+
# 后续代码不变(API 认证、模型加载、根路径首页、/v1/chat/completions 接口等)
|
| 22 |
+
# ...
|
| 23 |
+
|
| 24 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
|
| 25 |
class CrossEncoderWrapper:
|
| 26 |
def __init__(self):
|