用modelbox server启动流程图,暴露Restful接口

2023-12-07 00:04

本文主要是介绍用modelbox server启动流程图,暴露Restful接口,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

背景

假设你已经搭建了modelbox开发容器,能够使用webUI构建流程图。如果没有请参考昇腾npu上构建modelbox webUI开发容器教程。

现在,本文会说明,如何在终端用命令的方式将流程图暴露为服务,并能够在本地用postman访问。

本文参考ModelBox运行的"通过modelbox命令启动"一节

主要流程

首先,假设我们编写了如图的程序,其中foobar阶段会固定输出一个字符串。

foobar.py内容如下,固定会输出"Hello world!"

import _flowunit as modelboxclass FoobarFlowUnit(modelbox.FlowUnit):# Derived from modelbox.FlowUnitdef __init__(self):super().__init__()def open(self, config):# Open the flowunit to obtain configuration informationreturn modelbox.Status.StatusCode.STATUS_SUCCESSdef process(self, data_context):# Process the data# input datain_data = data_context.input("in_data")# output dataout_data = data_context.output("out_data")# Example process code.# Remove the following code and add your own code here.for buffer in in_data:add_buffer = modelbox.Buffer(self.get_bind_device(), "Hello world!")out_data.push_back(add_buffer)return modelbox.Status.StatusCode.STATUS_SUCCESSdef close(self):# Close the flowunitreturn modelbox.Status()def data_pre(self, data_context):# Before streaming data startsreturn modelbox.Status()def data_post(self, data_context):# After streaming data endsreturn modelbox.Status()

mnist_response.py的代码逻辑也很简单,固定输出上一步骤的字符串,内容如下:

import _flowunit as modelbox
import numpy as np
import jsonclass MnistResponseFlowUnit(modelbox.FlowUnit):def __init__(self):super().__init__()def open(self, config):return modelbox.Status.StatusCode.STATUS_SUCCESSdef process(self, data_context):in_data = data_context.input("in_data")out_data = data_context.output("out_data")for buffer in in_data:add_buffer = modelbox.Buffer(self.get_bind_device(), buffer.as_object())out_data.push_back(add_buffer)return modelbox.Status.StatusCode.STATUS_SUCCESSdef close(self):return modelbox.Status()def data_pre(self, data_context):return modelbox.Status()def data_post(self, data_context):return modelbox.Status()def data_group_pre(self, data_context):return modelbox.Status()def data_group_post(self, data_context):return modelbox.Status()

然后,在项目路径内graph/下的.toml文件内,修改暴露的端口,如下文显示端口暴露在8190


digraph mnist_sample {
node [shape=Mrecord]
httpserver_sync_receive [ type=flowunit flowunit=httpserver_sync_receive device=cpu time_out_ms=“5000” endpoint=“http://0.0.0.0:8190” max_requests=“100” ]

那么,如何不用webUI,将流程图启动暴露为Restful服务呢?

  1. 进入modelbox开发容器

  2. 进入目录/root/modelbox-service/conf

  3. 编辑modelbox.conf配置文件。把flow_path 属性指向你的项目的graph目录,比如在本文的mnist项目,流程图存储在/root/projects/mnist/src/graph目录下。内容如下:

    [server]
    ip = "0.0.0.0"
    port = "1104"
    flow_path = "/root/projects/mnist/src/graph/"# 后续略...
    
  4. 执行modelbox -c ./modelbox.conf -fV

然后,能看到终端输出日志:

[root@devserver-com conf]$ modelbox -c ./modelbox.conf -fV
[2023-12-06 20:35:17,711][ INFO][          main.cc:385 ] modelbox config path : ./modelbox.conf
[2023-12-06 20:35:17,711][ INFO][        server.cc:129 ] plugin list:
[2023-12-06 20:35:17,711][ INFO][        server.cc:131 ]  /usr/local/lib64/modelbox-plugin.so
[2023-12-06 20:35:17,711][ INFO][        server.cc:131 ]  /usr/local/lib64/modelbox-plugin-editor.so
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:68  ] create modelbox plugin
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:51  ] modelbox plugin init
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:61  ] run modelbox plugin on http://0.0.0.0:1104
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:73  ] modelbox plugin register handlers
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:74  ] regist url : /v1/modelbox/job
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:148 ] create local job
[2023-12-06 20:35:17,712][ INFO][modelbox_plugin.cc:192 ] Create local job /root/projects/mnist/src/graph//CMakeLists.txt
[2023-12-06 20:35:17,712][ERROR][          flow.cc:473 ] read config from  toml:/root/projects/mnist/src/graph//CMakeLists.txtfailed, err :Load config file failed, detail: [error] toml::parse_key_value_pair: missing key-value separator `=`--> /root/projects/mnist/src/graph//CMakeLists.txt|16 | cmake_minimum_required(VERSION 3.10)|                       ^--- should be `=`
[2023-12-06 20:35:17,712][ERROR][           job.cc:65  ] flow init failed: code: Fault, errmsg: Load config file failed, detail: [error] toml::parse_key_value_pair: missing key-value separator `=`--> /root/projects/mnist/src/graph//CMakeLists.txt...[2023-12-06 20:35:18,824][ INFO][ editor_plugin.cc:126 ] create modelbox editor plugin
[2023-12-06 20:35:18,824][ INFO][ editor_plugin.cc:104 ] modelbox editor plugin init
[2023-12-06 20:35:18,824][ INFO][ editor_plugin.cc:119 ] run editor on http://0.0.0.0:1104
[2023-12-06 20:35:18,824][ INFO][        server.cc:59  ] app server start
[2023-12-06 20:35:18,825][ INFO][   http_helper.cc:438 ] Start listen at 0.0.0.0:1104

然后用postman访问那个服务器IP的8190端口,并按预定的接口填写参数,即可发出Restful请求。如下图所示,返回了字符串,与预期一致。

这篇关于用modelbox server启动流程图,暴露Restful接口的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/463818

相关文章

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

kkFileView启动报错:报错2003端口占用的问题及解决

《kkFileView启动报错:报错2003端口占用的问题及解决》kkFileView启动报错因office组件2003端口未关闭,解决:查杀占用端口的进程,终止Java进程,使用shutdown.s... 目录原因解决总结kkFileViewjavascript启动报错启动office组件失败,请检查of

SQL Server 中的 WITH (NOLOCK) 示例详解

《SQLServer中的WITH(NOLOCK)示例详解》SQLServer中的WITH(NOLOCK)是一种表提示,等同于READUNCOMMITTED隔离级别,允许查询在不获取共享锁的情... 目录SQL Server 中的 WITH (NOLOCK) 详解一、WITH (NOLOCK) 的本质二、工作

SQL Server安装时候没有中文选项的解决方法

《SQLServer安装时候没有中文选项的解决方法》用户安装SQLServer时界面全英文,无中文选项,通过修改安装设置中的国家或地区为中文中国,重启安装程序后界面恢复中文,解决了问题,对SQLSe... 你是不是在安装SQL Server时候发现安装界面和别人不同,并且无论如何都没有中文选项?这个问题也

Linux下在线安装启动VNC教程

《Linux下在线安装启动VNC教程》本文指导在CentOS7上在线安装VNC,包含安装、配置密码、启动/停止、清理重启步骤及注意事项,强调需安装VNC桌面以避免黑屏,并解决端口冲突和目录权限问题... 目录描述安装VNC安装 VNC 桌面可能遇到的问题总结描js述linux中的VNC就类似于Window

linux下shell脚本启动jar包实现过程

《linux下shell脚本启动jar包实现过程》确保APP_NAME和LOG_FILE位于目录内,首次启动前需手动创建log文件夹,否则报错,此为个人经验,供参考,欢迎支持脚本之家... 目录linux下shell脚本启动jar包样例1样例2总结linux下shell脚本启动jar包样例1#!/bin

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

SQL Server配置管理器无法打开的四种解决方法

《SQLServer配置管理器无法打开的四种解决方法》本文总结了SQLServer配置管理器无法打开的四种解决方法,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录方法一:桌面图标进入方法二:运行窗口进入检查版本号对照表php方法三:查找文件路径方法四:检查 S