用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

相关文章

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

MyBatis-Flex BaseMapper的接口基本用法小结

《MyBatis-FlexBaseMapper的接口基本用法小结》本文主要介绍了MyBatis-FlexBaseMapper的接口基本用法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具... 目录MyBATis-Flex简单介绍特性基础方法INSERT① insert② insertSelec

Spring排序机制之接口与注解的使用方法

《Spring排序机制之接口与注解的使用方法》本文介绍了Spring中多种排序机制,包括Ordered接口、PriorityOrdered接口、@Order注解和@Priority注解,提供了详细示例... 目录一、Spring 排序的需求场景二、Spring 中的排序机制1、Ordered 接口2、Pri

Idea实现接口的方法上无法添加@Override注解的解决方案

《Idea实现接口的方法上无法添加@Override注解的解决方案》文章介绍了在IDEA中实现接口方法时无法添加@Override注解的问题及其解决方法,主要步骤包括更改项目结构中的Languagel... 目录Idea实现接China编程口的方法上无法添加@javascriptOverride注解错误原因解决方

Windows设置nginx启动端口的方法

《Windows设置nginx启动端口的方法》在服务器配置与开发过程中,nginx作为一款高效的HTTP和反向代理服务器,被广泛应用,而在Windows系统中,合理设置nginx的启动端口,是确保其正... 目录一、为什么要设置 nginx 启动端口二、设置步骤三、常见问题及解决一、为什么要设置 nginx

springboot启动流程过程

《springboot启动流程过程》SpringBoot简化了Spring框架的使用,通过创建`SpringApplication`对象,判断应用类型并设置初始化器和监听器,在`run`方法中,读取配... 目录springboot启动流程springboot程序启动入口1.创建SpringApplicat

树莓派启动python的实现方法

《树莓派启动python的实现方法》本文主要介绍了树莓派启动python的实现方法,文中通过图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录一、RASPBerry系统设置二、使用sandroidsh连接上开发板Raspberry Pi三、运

查询SQL Server数据库服务器IP地址的多种有效方法

《查询SQLServer数据库服务器IP地址的多种有效方法》作为数据库管理员或开发人员,了解如何查询SQLServer数据库服务器的IP地址是一项重要技能,本文将介绍几种简单而有效的方法,帮助你轻松... 目录使用T-SQL查询方法1:使用系统函数方法2:使用系统视图使用SQL Server Configu

SQL Server数据库迁移到MySQL的完整指南

《SQLServer数据库迁移到MySQL的完整指南》在企业应用开发中,数据库迁移是一个常见的需求,随着业务的发展,企业可能会从SQLServer转向MySQL,原因可能是成本、性能、跨平台兼容性等... 目录一、迁移前的准备工作1.1 确定迁移范围1.2 评估兼容性1.3 备份数据二、迁移工具的选择2.1