<commit_before>from flask import Flask, render_template, jsonify, request, Response
import joblib
import argparse
import os
import json
from scoring_utils import get_comment
import time

app = Flask(__name__)
app.debug = True


@app.route('/')
def main():
    return render_template('index.html')

@app.route('/wiki-talk/')
def main2():
    return render_template('index.html')


@app.route('/api')
def get_insult_scores():
    print(request.args)
    t1 = time.time()

    assert(request.args.get('model', '') in models)
    assert('text' in request.args or 'rev_id' in request.args)

    ret = {}

    if 'rev_id' in request.args:
        text = get_comment(request.args['rev_id'])
        ret['text'] = text
    else:
        text = request.args['text']
    
    if text:
        prob = models[request.args['model']].predict_proba([text])[0][1]
        ret['p'] = '%0.2f' % prob
    
    t2 = time.time()
    print('Total Time:', t2-t1)
    return jsonify(ret)


@app.after_request
def after_request(response):
  response.headers.add('Access-Control-Allow-Origin', '*')
  response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
  return response


parser = argparse.ArgumentParser()
parser.add_argument(
    '--model_paths', required=False,
    default='model_paths.json',
    help='path to json dictionary of model names and paths'
)

parser.add_argument(
    '--local', 
    action="store_true",
    help='run on local host '
)

args, unknown = parser.parse_known_args()
model_paths = json.load(open(args.model_paths))
models = {k : joblib.load(v) for k,v in model_paths.items()}


if __name__ == "__main__":
    if args.local:
        app.run(port=5002)
    else:
        app.run(host='0.0.0.0', port=8000)<commit_msg>modified modelpaths default<commit_after>from flask import Flask, render_template, jsonify, request, Response
import joblib
import argparse
import os
import json
from scoring_utils import get_comment
import time

app = Flask(__name__)
app.debug = True


@app.route('/')
def main():
    return render_template('index.html')

@app.route('/wiki-talk/')
def main2():
    return render_template('index.html')


@app.route('/api')
def get_insult_scores():
    print(request.args)
    t1 = time.time()

    assert(request.args.get('model', '') in models)
    assert('text' in request.args or 'rev_id' in request.args)

    ret = {}

    if 'rev_id' in request.args:
        text = get_comment(request.args['rev_id'])
        ret['text'] = text
    else:
        text = request.args['text']
    
    if text:
        prob = models[request.args['model']].predict_proba([text])[0][1]
        ret['p'] = '%0.2f' % prob
    
    t2 = time.time()
    print('Total Time:', t2-t1)
    return jsonify(ret)


@app.after_request
def after_request(response):
  response.headers.add('Access-Control-Allow-Origin', '*')
  response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
  return response


parser = argparse.ArgumentParser()
parser.add_argument(
    '--model_paths', required=False,
    default='/data/project/wiki-talk2/www/python/talk_page_abuse/app/model_paths_labs.json',
    help='path to json dictionary of model names and paths'
)

parser.add_argument(
    '--local', 
    action="store_true",
    help='run on local host '
)

args, unknown = parser.parse_known_args()
model_paths = json.load(open(args.model_paths))
models = {k : joblib.load(v) for k,v in model_paths.items()}


if __name__ == "__main__":
    if args.local:
        app.run(port=5002)
    else:
        app.run(host='0.0.0.0', port=8000)
{'fraction_non_alphanumeric': 0.15135279935708545, 'fraction_numerical': 0.011518885614787035, 'mean_word_length': 3.7146464646464645, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1108628', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1246, 'n_words': 263}