Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bfgf52 opened this issue Jun 27, 2023 · 1 comment
Assignees
Labels
question Further information is requested triage

Comments

@bfgf52
Copy link

bfgf52 commented Jun 27, 2023

请提出你的问题

这是服务端代码

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

@bfgf52 bfgf52 added the question Further information is requested label Jun 27, 2023
@w5688414
Copy link
Contributor

w5688414 commented May 8, 2024

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

@paddle-bot paddle-bot bot closed this as completed May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested triage
Projects
None yet
Development

No branches or pull requests

3 participants