Updated Dockerfile

This commit is contained in:
lkrsnik 2023-12-06 16:35:15 +01:00
parent e71d656d0e
commit ab66eeb6e8
2 changed files with 217 additions and 213 deletions

View File

@ -5,4 +5,4 @@ RUN pip install --upgrade pip
RUN pip install waitress RUN pip install waitress
RUN pip install . RUN pip install .
CMD ["waitress-serve", "--call", "app:app"] CMD ["waitress-serve", "--call", "app:create_app"]

40
app.py
View File

@ -9,17 +9,18 @@ import time
import requests import requests
from flask import Flask, render_template, request, send_file, redirect, url_for from flask import Flask, render_template, request, send_file, redirect, url_for
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from stark import run from stark import run
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads' UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = {'conllu'} ALLOWED_EXTENSIONS = {'conllu'}
DAYS_BEFORE_DELETION = 1 DAYS_BEFORE_DELETION = 1
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def create_default_configs(): def create_app():
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def create_default_configs():
configs = {} configs = {}
# mandatory parameters # mandatory parameters
configs['input_path'] = 'data/sl_ssj-ud_v2.4.conllu' configs['input_path'] = 'data/sl_ssj-ud_v2.4.conllu'
@ -55,36 +56,36 @@ def create_default_configs():
return configs return configs
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and \ return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/upload') @app.route('/upload')
def upload_file2(): def upload_file2():
return render_template('upload.html') return render_template('upload.html')
@app.route('/uploader', methods=['GET', 'POST']) @app.route('/uploader', methods=['GET', 'POST'])
def upload_file(): def upload_file():
if request.method == 'POST': if request.method == 'POST':
f = request.files['file'] f = request.files['file']
f.save(secure_filename(f.filename)) f.save(secure_filename(f.filename))
return 'file uploaded successfully' return 'file uploaded successfully'
@app.route('/about', methods=['GET']) @app.route('/about', methods=['GET'])
def about(): def about():
return render_template('about.html') return render_template('about.html')
# @app.route('/result/<result_id>/download', methods=['GET']) # @app.route('/result/<result_id>/download', methods=['GET'])
# def download_result(result_id): # def download_result(result_id):
# return # return
@app.route('/result/<result_id>', methods=['GET', 'POST']) @app.route('/result/<result_id>', methods=['GET', 'POST'])
def result(result_id): def result(result_id):
if request.method == 'POST': if request.method == 'POST':
for filename in os.listdir('media'): for filename in os.listdir('media'):
@ -125,8 +126,8 @@ def result(result_id):
return render_template('result.html', head_row=head, content=content_dict) return render_template('result.html', head_row=head, content=content_dict)
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def index(): def index():
if request.method == 'POST': if request.method == 'POST':
form = request.form form = request.form
configs = {} configs = {}
@ -258,6 +259,9 @@ def index():
# return render_template('index.html') # return render_template('index.html')
return render_template('index.html') return render_template('index.html')
return app
if __name__ == '__main__': if __name__ == '__main__':
app = create_app()
app.run(debug=True) app.run(debug=True)