paddlenlp
45 строк · 1.7 Кб
1# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import argparse16import json17
18import requests19
20parser = argparse.ArgumentParser()21parser.add_argument(22"--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization."23)
24parser.add_argument("--batch_size", default=2, type=int, help="Batch size per GPU/CPU for predicting.")25args = parser.parse_args()26
27url = "http://0.0.0.0:8189/models/cblue_spo"28headers = {"Content-Type": "application/json"}29
30if __name__ == "__main__":31texts = ["骶髂关节炎是明确诊断JAS的关键条件。若有肋椎关节病变会使胸部扩张度减小。", "稳定型缺血性心脏疾病@肥胖与缺乏活动也导致高血压增多。"]32texts = [[x.lower() for x in text] for text in texts]33data = {34"data": {35"text": texts,36},37"parameters": {38"max_seq_len": args.max_seq_len,39"batch_size": args.batch_size,40"return_attention_mask": True,41"is_split_into_words": True,42},43}44r = requests.post(url=url, headers=headers, data=json.dumps(data))45print(r.text)46