diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/forms.py | 7 | ||||
-rw-r--r-- | app/prod/config.json | 10 | ||||
-rw-r--r-- | app/views.py | 30 |
3 files changed, 39 insertions, 8 deletions
diff --git a/app/forms.py b/app/forms.py index 47f423d..3a06f27 100644 --- a/app/forms.py +++ b/app/forms.py @@ -1,6 +1,6 @@ from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileRequired, FileAllowed -from wtforms import StringField, DecimalField +from wtforms import StringField, DecimalField, IntegerField from wtforms.validators import DataRequired, Email @@ -32,4 +32,7 @@ class curieForm(FlaskForm): email = StringField('Email', validators=[DataRequired(), Email()]) class statusForm(FlaskForm): - jobID = StringField('Job ID',validators=[DataRequired()])
\ No newline at end of file + jobID = StringField('Job ID',validators=[DataRequired()]) + +class generateSMILES(FlaskForm): + n = IntegerField('Number of Molecules to Generate',default=1,validators=[DataRequired()])
\ No newline at end of file diff --git a/app/prod/config.json b/app/prod/config.json index 4b72262..ccab45f 100644 --- a/app/prod/config.json +++ b/app/prod/config.json @@ -20,11 +20,11 @@ "finetune_epochs": 12, "finetune_batch_size": 1, "finetune_data_filename": "./datasets/protease_inhibitors_for_fine-tune.txt", - "config_file": "experiments/base_experiment/LSTM_Chem/config.json", + "config_file": "app/prod/config.json", "exp_dir": "experiments/2020-07-13/LSTM_Chem", - "tensorboard_log_dir": "experiments/2020-07-13/LSTM_Chem/logs/", - "checkpoint_dir": "experiments/2020-07-13/LSTM_Chem/checkpoints/", + "tensorboard_log_dir": "app/prod/logs/", + "checkpoint_dir": "app/prod/checkpoints/", "train_smi_max_len": 128, - "model_arch_filename": "experiments/2020-07-13/LSTM_Chem/model_arch.json", - "model_weight_filename": "experiments/2020-07-13/LSTM_Chem/checkpoints/LSTM_Chem-42-0.23.hdf5" + "model_arch_filename": "app/prod/model_arch.json", + "model_weight_filename": "app/prod/checkpoints/LSTM_Chem-42-0.23.hdf5" }
\ No newline at end of file diff --git a/app/views.py b/app/views.py index c59f31e..488053c 100644 --- a/app/views.py +++ b/app/views.py @@ -12,7 +12,7 @@ from string import digits, ascii_lowercase # Note: that when using Flask-WTF we need to import the Form Class that we created # in forms.py -from .forms import MyForm, curieForm, statusForm +from .forms import MyForm, curieForm, statusForm, generateSMILES def gen_word(N, min_N_dig, min_N_low): choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low @@ -110,6 +110,34 @@ def wtform(): flash_errors(myform) return render_template('wtform.html', form=myform) +try: + from lstm_chem.utils.config import process_config + from lstm_chem.model import LSTMChem + from lstm_chem.generator import LSTMChemGenerator + config = process_config("app/prod/config.json") + modeler = LSTMChem(config, session="generate") + gen = LSTMChemGenerator(modeler) + print("Testing Model") + gen.sample(1) +except: + print("ok") + + +@app.route('/Generate', methods=['GET','POST']) +def generate(): + """Generate novel drugs""" + form = generateSMILES() + + with open("./app/prod/config.json") as config: + import json + j = json.loads(config.read()) + print(j["exp_name"]) + + if request.method == 'POST' and form.validate_on_submit(): + result = gen.sample(form.n.data) + return render_template('generate.html',expName=j["exp_name"],epochs=j["num_epochs"],optimizer=j["optimizer"].capitalize(), form=form,result=result) + + return render_template('generate.html',expName=j["exp_name"],epochs=j["num_epochs"],optimizer=j["optimizer"].capitalize(), form=form) @app.route('/Dock', methods=['GET', 'POST']) def dock_upload(): |