Update handler.py
Browse files- handler.py +5 -9
handler.py
CHANGED
@@ -3,15 +3,11 @@ from transformers import pipeline
|
|
3 |
|
4 |
class EndpointHandler():
|
5 |
def __init__(self, path=""):
|
6 |
-
#
|
7 |
-
self.pipeline = pipeline("
|
8 |
|
9 |
-
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
10 |
-
#
|
11 |
inputs = data.get("inputs", "")
|
12 |
-
|
13 |
-
# 使用对话模型生成响应
|
14 |
-
conversation = self.pipeline(inputs)
|
15 |
-
|
16 |
-
# 返回模型的响应
|
17 |
return {"response": conversation.generated_responses[0]}
|
|
|
3 |
|
4 |
class EndpointHandler():
|
5 |
def __init__(self, path=""):
|
6 |
+
# 初始化方法,加载模型
|
7 |
+
self.pipeline = pipeline("text-classification", model=path)
|
8 |
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
10 |
+
# 处理输入数据并返回预测结果
|
11 |
inputs = data.get("inputs", "")
|
12 |
+
prediction = self.pipeline(inputs)
|
|
|
|
|
|
|
|
|
13 |
return {"response": conversation.generated_responses[0]}
|