<commit_before>
from __future__ import absolute_import

from flask import Flask, redirect #import objects from the Flask model
import os, platform

app = Flask(__name__)
sklearn2sql_uri = os.environ.get("SKLEARN2SQL_URI", "http://c:1888")

@app.route('/', methods=['GET'])
def test():
    return redirect(sklearn2sql_uri, code=307)

@app.route('/models', methods=['GET'])
def returnAllModels():
    return redirect(sklearn2sql_uri, code=307)



@app.route('/model/<string:name>', methods=['GET'])
def returnOneModel(name):
    return redirect(sklearn2sql_uri + "/model/" + name, code=307)


# POST requests

@app.route('/model', methods=['POST'])
def addOneModel():
    return redirect(sklearn2sql_uri + "/model", code=307)

# PUT requests 

if __name__ == '__main__':
    print(platform.platform())
    print(platform.uname())
    print(platform.processor())
    print(platform.python_implementation(), platform.python_version());
    print(os.environ);
    port = int(os.environ.get("PORT", 1888))
    app.run(host='0.0.0.0', port=port, debug=True)
<commit_msg>Build a hand-crafted response object by calling instead of a simple redirect<commit_after>
from __future__ import absolute_import

from flask import Flask, redirect, request #import objects from the Flask model
import os, platform
import requests, json

app = Flask(__name__)
sklearn2sql_uri = os.environ.get("SKLEARN2SQL_URI", "http://c:1888")


def get_post_response(request1):
    # request1 = request
    print(request1.json)
    r = requests.post(sklearn2sql_uri + "/model", json=request1.json)
    print("JSON", r.json())
    response = app.response_class(
        response=json.dumps(r.json()),
        status=200,
        mimetype='application/json'
    )
    # json.dumps(data)
    return response


@app.route('/', methods=['GET'])
def test():
    return redirect(sklearn2sql_uri, code=307)

@app.route('/models', methods=['GET'])
def returnAllModels():
    return redirect(sklearn2sql_uri, code=307)



@app.route('/model/<string:name>', methods=['GET'])
def returnOneModel(name):
    return redirect(sklearn2sql_uri + "/model/" + name, code=307)


# POST requests

@app.route('/model', methods=['POST'])
def addOneModel():
    # return redirect(sklearn2sql_uri + "/model", code=307)
    return get_post_response(request)

# PUT requests 

if __name__ == '__main__':
    print(platform.platform())
    print(platform.uname())
    print(platform.processor())
    print(platform.python_implementation(), platform.python_version());
    print(os.environ);
    port = int(os.environ.get("PORT", 1888))
    app.run(host='0.0.0.0', port=port, debug=True)

{'fraction_non_alphanumeric': 0.155165840640488, 'fraction_numerical': 0.025924513915364086, 'mean_word_length': 4.767032967032967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3708667', 'n_tokens_mistral': 897, 'n_tokens_neox': 856, 'n_words': 184}