Created
June 4, 2018 20:09
-
-
Save mbebenita/8a418a407fadf4aa2d0cec4e47f223a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
'''Sequence to sequence grammar check. | |
''' | |
from flask import Flask, jsonify, request | |
import math | |
from keras.models import Model | |
from keras.layers import Input, LSTM, CuDNNLSTM, Dense, Embedding, Reshape, Concatenate, Lambda, Conv1D | |
from keras import backend as K | |
import numpy as np | |
import sys | |
import encoding | |
import deepproof_model | |
import re | |
import tensorflow as tf | |
from keras.backend.tensorflow_backend import set_session | |
config = tf.ConfigProto() | |
config.gpu_options.per_process_gpu_memory_fraction = 0.29 | |
set_session(tf.Session(config=config)) | |
encoder_model, decoder_model, model = deepproof_model.create(False) | |
model.load_weights('proof6a2.h5') | |
def check(line): | |
input_seq = encoding.encode_string(line, 300, 0) | |
input_seq = np.reshape(input_seq, (1, input_seq.shape[0], 1)) | |
return deepproof_model.decode_sequence([encoder_model, decoder_model], input_seq) | |
print(check("Starting up the process, not sure why I need to do this, but it fails otherwise.")) | |
app = Flask(__name__) | |
@app.after_request | |
def after_request(response): | |
header = response.headers | |
header['Access-Control-Allow-Origin'] = '*' | |
header['Access-Control-Allow-Headers'] = 'Accept,Content-Type' | |
return response | |
@app.route("/api", methods=["GET", "POST"]) | |
def hello(): | |
print(request.json) | |
result = re.search(r"\|(.*?)\|", check(request.json['text'])).group(1) | |
return jsonify({'result': result}), 200 | |
app.run(host = "localhost", port=5000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment