用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

相关文章

spring中的ImportSelector接口示例详解

《spring中的ImportSelector接口示例详解》Spring的ImportSelector接口用于动态选择配置类,实现条件化和模块化配置,关键方法selectImports根据注解信息返回... 目录一、核心作用二、关键方法三、扩展功能四、使用示例五、工作原理六、应用场景七、自定义实现Impor

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

SQL Server数据库死锁处理超详细攻略

《SQLServer数据库死锁处理超详细攻略》SQLServer作为主流数据库管理系统,在高并发场景下可能面临死锁问题,影响系统性能和稳定性,这篇文章主要给大家介绍了关于SQLServer数据库死... 目录一、引言二、查询 Sqlserver 中造成死锁的 SPID三、用内置函数查询执行信息1. sp_w

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根

MybatisPlus service接口功能介绍

《MybatisPlusservice接口功能介绍》:本文主要介绍MybatisPlusservice接口功能介绍,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录Service接口基本用法进阶用法总结:Lambda方法Service接口基本用法MyBATisP

Java中实现线程的创建和启动的方法

《Java中实现线程的创建和启动的方法》在Java中,实现线程的创建和启动是两个不同但紧密相关的概念,理解为什么要启动线程(调用start()方法)而非直接调用run()方法,是掌握多线程编程的关键,... 目录1. 线程的生命周期2. start() vs run() 的本质区别3. 为什么必须通过 st

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存