2017-07-19 30 views
-1

目前,我写了数据处理的工作流程,并试图将其部署在Web服务器上,在整个工作流程。我不得不使用两种不同的语言(Java和Python)。 我有一个HTML表单获取用户输入,然后我的Python应用程序烧瓶将处理该输入并将其传递到使用内置在Python通话功能的Java程序。然后我的烧瓶应用程序将采取输出,再次处理它,并将其返回给用户。建议上部署了严重的脚本到Web服务器(使用Java,Python)

我能在我的本地Linux系统上运行的整个工作流程完美,我打开HTML表单,填写输入并提交,然后将浏览器重定向我的结果页面,一点问题都没有。但是当我尝试在我们的实验室使用的文字印刷机上部署这整个管道时,我无法使其工作。我仍然可以运行烧瓶应用程序,但它根本不会听取HTML表单上的发布请求。我已附加我的烧瓶应用程序和HTML代码。有没有我没有设置的权利?或者是有一些类型的系统,我可以只使用它在本地设置了整个事情,并一次全部部署管道到服务器上的?我一直在寻找python烧瓶部署建议,但其中大多数只是让我非常困惑。如果任何人都可以给我一些有关将这个管道部署到服务器上的建议,那将是非常棒的。任何建议表示赞赏!

<form action = "http://localhost:5000/login" method = "POST" 
 
    enctype="multipart/form-data"> 
 
    <fieldset> 
 
    <legend>Plot Config:</legend> 
 
    <br>Please upload your input file:<br> 
 
    <input type="file" name="file" accept="*/*">  
 
    <br><br> \t 
 
\t 
 

 
    <br>Classifer type:<br> 
 
    <input type="radio" name="classifier" value="SVM" checked>Support Vector Machine<br> 
 
    <input type="radio" name="classifier" value="NB">Naive Bayes<br> 
 
    <input type="radio" name="classifier" value="RF">Random Forest<br> 
 

 
    <br>Number of estimators (if you chose Random Forest as your classifier):<br> 
 
    <input type="text" name="estimators" value="10"><br> \t 
 

 

 
    <br>Would you like to average your result?:<br> 
 
    <input type="radio" name="avg" value="Yes" checked>Yes<br> 
 
    <input type="radio" name="avg" value="No"> No<br> \t 
 
    
 

 
    <br>Feature Selection interval:<br> 
 
    <input type="text" name="interval" value=10><br> \t 
 

 

 
    <br>Plot feature range:<br> 
 
    <input type="text" name="plotrange" value=85><br> 
 

 
    <br>Plot lengend size:<br> 
 
    <input type="text" name="legendsize" value=7.5><br>  
 
    \t \t \t 
 
    <br>Plot line width:<br> 
 
    <input type="text" name="plotlinewidth" value=2><br> 
 

 
    <br>Legend title:<br> 
 
    <input type="text" name="legendtitle"><br> 
 

 

 

 

 

 

 

 

 
<br><br> \t 
 
    <input type="reset"> 
 
    <input type="submit" value="Submit"> 
 

 
    
 

 
    </fieldset> 
 
</form>

from flask import Flask, redirect, url_for, request,send_file 
import configparser 
from werkzeug import secure_filename 
import os 
from subprocess import call 

app = Flask(__name__) 

@app.route('/success/<name>') 
def success(name): 
    return 'welcome! %s' % name 

@app.route('/get_image') 
def get_image(): 
    if request.args.get('type') == '1': 
     filename = 'download.jpg' 
    else: 
     filename = 'download.jpg' 
    return send_file(filename, mimetype='image/jpg')  

@app.route('/login',methods = ['POST', 'GET']) 
def login(): 
    if request.method == 'POST': 
     f=request.files['file'] 
     workdir=os.path.join(os.getcwd(), 'Input(LeaveOneOut)',f.filename) 
     print workdir  
     f.save(workdir) 
     classifier = request.form['classifier'] 
     estimators=request.form['estimators'] 
     avg=request.form['avg'] 
     interval=request.form['interval'] 
     plotrange=request.form['plotrange'] 
     legendsize=request.form['legendsize'] 
     plotlinewidth=request.form['plotlinewidth'] 
     legendtitle=request.form['legendtitle'] 
     testoutput=classifier+" "+estimators+" "+avg+" "+interval+" "+plotrange+" "+legendsize+" "+plotlinewidth+" "+legendtitle   
     settings = configparser.ConfigParser() 
     settings._interpolation = configparser.ExtendedInterpolation() 
     settings.read('LeaveOneOutConfig.txt') 
     settings.set('SectionOne', 'Classifier', str(classifier)) 
     settings.set('SectionOne', 'number of estimators', str(estimators)) 
     settings.set('SectionOne', 'average the result', str(avg)) 
     settings.set('SectionOne', 'feature selection interval', str(interval)) 
     settings.set('SectionOne', 'plot feature range', str(plotrange)) 
     settings.set('SectionOne', 'plot lengend size', str(legendsize)) 
     settings.set('SectionOne', 'plot line width', str(plotlinewidth)) 
     settings.set('SectionOne', 'dataset type name', str(legendtitle))   
     call(["python", "LeaveOneOut.py"]) 





     with open('LeaveOneOutConfig.txt', 'wb') as configfile: 
      settings.write(configfile)   

     return redirect(url_for('get_image')) 
     return redirect(url_for('success',name =testoutput)) 
if __name__ == '__main__': 
    app.run(debug = True) 
+0

http://flask.pocoo.org/docs/dev/deploying/ – davidism

+0

感谢您的帮助。尽管我在发布这个问题之前已经多次阅读过该页面。说实话,感觉伤人的,你想,当我develping烧瓶程序,我没有读过烧瓶文件。 – Coco

回答

0

所以我终于想通了,如果您想的内容是公开的,你需要使服务器运行在0.0.0.0和端口80 在我的情况我将最后一行更改为app.run(“0.0.0.0”,port = 80)。另外,烧瓶连接服务器似乎很不稳定,实际上这是在烧瓶文档中写的,您应该使用其他部署选项。我使用了易于使用且对我来说稳定的gunicorn。希望这有助于解决同样的问题。