PaddlePaddle / PaddleNLP

👑 Easy-to-use and powerful NLP and LLM library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis etc.
https://paddlenlp.readthedocs.io
Apache License 2.0
11.93k stars 2.91k forks source link

[Question]: 如何在一个SimpleServer里面部署2个不同的taskflow任务呢? #6260

Open bfgf52 opened 1 year ago

bfgf52 commented 1 year ago

请提出你的问题

这是服务端代码

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

w5688414 commented 4 months ago

您好,SimpleServer已经停止更新了,不过SimpleServer是基于fastAPI来写的,您可以直接使用fastAPI,另外,欢迎开发者进行贡献。