[英]Run Python Script into Flask
我有一个桌面应用程序,可以检测使用opencv和numpy用python脚本编写的面孔。 我想将这些python文件放入flask并运行它,它会不会出现问题? 喜欢
import cv2
import numpy as np
from flask import Flask
app = Flask(__name__)
## define my functions here
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
#call the functions here
app.run()
那行得通吗? 如果没有,我如何将其包括在内? 谢谢!
是的,它将起作用,您应该知道的一件事是,如果您像下面这样,则在处理完成之后,HTTP请求才会返回,例如
@app.route('/webcam')
def webcam_capture():
"""
Returns a picture snapshot from the webcam
"""
image = cv2... # call a function to get an image
response = make_response(image) # make an HTTP response with the image
response.headers['Content-Type'] = 'image/jpeg'
response.headers['Content-Disposition'] = 'attachment; filename=img.jpg'
return response
否则,如果您输入如下的主要功能
if __name__ == '__main__':
# <-- No need to put things here, unless you want them to run before
# the app is ran (e.g. you need to initialize something)
app.run()
然后,直到完成初始化/处理后,烧瓶应用程序才能启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.