Closed
Description
请提出你的问题
这是服务端代码
from paddlenlp import Taskflow, SimpleServer
car_schema = ["大众","丰田","别克","奥迪","本田","奔驰","无"]
car_utc = Taskflow("zero_shot_text_classification",
model="utc-nano",
schema=car_schema,
precision="fp32")
book_schema = ["水浒传","三国演义","西游记","红楼梦","无"]
book_utc = Taskflow("zero_shot_text_classification",
model="utc-nano",
schema=book_schema,
precision="fp32")
app = SimpleServer()
app.register_taskflow("taskflow/car_utc", car_utc)
app.register_taskflow("taskflow/book_utc", book_utc)
这是客户端代码
import json
from pprint import pprint
import requests
if __name__ == "__main__":
url = "http://127.0.0.1:8990/taskflow/car_utc"
headers = {"Content-Type": "application/json"}
texts = ["三国志"]
data = {"data": {"text": texts}}
r = requests.post(url=url, headers=headers, data=json.dumps(data))
datas = json.loads(r.text)
pprint(datas)
results = []
for item in datas['result']:
if len(item['predictions']) > 0:
label = item['predictions'][0]['label']
score = item['predictions'][0]['score']
else:
label = ''
score = 0
results.append({"text":item['text_a'],"label":label,"score":score})
print(results)
# [{'text': '三国志', 'label': '三国演义', 'score': 0.9488116450766004}]
问题是:为什么我调用的是car_utc服务,但是预测结果出来的labels是book_schema里面的结果,请问要如何使用,才能使得car_utc对应的是car_schema呢
paddlenlp版本:2.5.2.post