Currently, I am writing a workflow for data processing and trying to deploy it on a web server, in the whole workflow. I had to use two different languages (Java and Python). I have an HTML form that takes input from the user, then my python flask app will process that input and pass it to a java program using call function built in python. Then my flask app will take the output, process it again, and return it to the user.
I am able to run the whole workflow on my local Linux system perfectly, I open the HTML form, fill the input and submit, then the browser redirects me to the result page with no problem at all. But when I try to deploy this whole pipeline on a word press server our lab uses, I can't make it work. I can still run the flask app but it does not listen to the post request on the HTML form at all. I have attached my flask app and HTML code. Is there something I wasn't setting right? Or is there some kind of system that I can just use it to set the whole thing locally and deploy the pipeline onto the server all at once? I have been looking through python flask deployment suggestion but most of them just get me very confused. It would be great if anyone can give me some helpful advice on deploying this pipeline onto the server. Any advice is appreciated!
<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>
<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>
<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>
<br>Feature Selection interval:<br>
<input type="text" name="interval" value=10><br>
<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>
<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>
<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)