当前位置:网站首页>模型部署篇
模型部署篇
2022-06-10 08:05:00 【算法之名】
服务器部署
Flask
Flask是一个使用Python编写的轻量级Web应用框架。
安装Flask
pip install Flask现在我们开始一个Hello World。
from flask import Flask, requestapp = Flask(__name__)@app.route("/hello")def helloword(): return "<h1>Hello World</h1>"if __name__ == '__main__': app.run(host='192.168.0.138', port=8090, debug=True)
运行后显示
* Serving Flask app "flask_web" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Running on http://192.168.0.138:8090/ (Press CTRL+C to quit) * Restarting with fsevents reloader * Debugger is active! * Debugger PIN: 235-830-661我们在浏览器中输入http://192.168.0.138:8090/hello,得到

现在我们再增加一个非常重要的方法,图片上传,提供给模型进行前向推理。
from flask import Flask, requestimport osapp = Flask(__name__)@app.route("/hello")def helloword(): return "<h1>Hello World</h1>"@app.route("/upload", methods=['POST', 'GET'])def upload(): f = request.files.get('file') print(f) upload_path = os.path.join("/Users/admin/Documents/tmp/tmp." + f.filename.split('.')[-1]) print(upload_path) f.save(upload_path) return upload_pathif __name__ == '__main__': app.run(host='192.168.0.138', port=8090, debug=True)
重新启动后,我们使用postman来上传文件

并在我们编辑的路径中找到该文件

运行结果
<FileStorage: '1.jpeg' ('image/jpeg')>/Users/admin/Documents/tmp/tmp.jpeg192.168.0.138 - - [02/Jun/2022 09:50:55] "POST /upload HTTP/1.1" 200 -动态启动服务
安装gunicorn
pip install gunicorn进入flask python文件的目录,我这里是
cd Downloads/PycharmProjects/untitled1/flask-web/运行命令
gunicorn -b 192.168.0.138:8000 -w 2 flask_web:app这里使用的端口号不需要跟代码中的相同,可以任意定义
运行日志
[2022-06-02 10:31:12 +0800] [1980] [INFO] Starting gunicorn 20.1.0[2022-06-02 10:31:12 +0800] [1980] [INFO] Listening at: http://192.168.0.138:8090 (1980)[2022-06-02 10:31:12 +0800] [1980] [INFO] Using worker: sync[2022-06-02 10:31:12 +0800] [1983] [INFO] Booting worker with pid: 1983[2022-06-02 10:33:40 +0800] [1980] [CRITICAL] WORKER TIMEOUT (pid:1983)[2022-06-02 10:33:40 +0800] [1983] [INFO] Worker exiting (pid: 1983)[2022-06-02 10:33:40 +0800] [1989] [INFO] Booting worker with pid: 1989
边栏推荐
猜你喜欢

Map的entrySet实现map按key升序排列或value降序排列

二极管、三极管

What brand is a cheap Bluetooth headset? Four cheap and easy-to-use Bluetooth headsets on the digital control panel

618 大促来袭,浅谈如何做好大促备战

putty里中文显示为框框和乱码无法显示中文解决
![[chapter 65 of the flutter problem series] a solution to setting the maximum height of showmodalbottomsheet in the flutter is invalid](/img/a3/7db76a03bfa6c036e576074af84428.png)
[chapter 65 of the flutter problem series] a solution to setting the maximum height of showmodalbottomsheet in the flutter is invalid

【Flutter 问题系列第 65 篇】在 Flutter 设置 showModalBottomSheet 最大高度无效的解决方案

Cloud native network edge -- cilium overview

Swagger quick use

List, set and sorted of redis data types_ Set sort
随机推荐
How can smart cities accelerate their development with the help of cloud computing?
DataGridView数据的增删改查,XML保存参数(C#)
Global industry analysis report of proton therapy technology in 2022
浏览器中如何使用 module export import: Uncaught SyntaxError: Cannot use import statement outside a module 问题
Online legal aid service 2022 Global Industry Analysis Report
How to use module export import: uncaught syntaxerror: cannot use import statement outside a module
Using pyqt5 + Agora + leancloud to realize online class based on student fatigue detection
Using fast and slow pointer to find the midpoint of linked list
关于发布《深圳市培育发展半导体与集成电路产业集群行动计划(2022-2025年)》的通知
Convenient ultraviolet air purifier 2022 Global Industry Analysis Report
[apio2022] Mars - structure, state compression
力扣(LeetCode)160. 相交链表(2022.06.09)
WPF data binding (III)
How to extend the validity of a vos3000 account after it expires?
2022年最新吉林建筑安全员模拟题库及答案
markdown md 文件编辑器测试使用说明
A practice of encrypting server 3D model resources
easyexcel实现简单的上传下载
String problem summary
关于发布《深圳市培育发展生物医药产业集群行动计划(2022-2025年)》的通知