2017-07-19 32 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。希望這有助於解決同樣的問題。