<commit_before>#!/usr/bin/env python

import argparse
import flask
import ConfigParser
import mimetypes
import os
import re
import sys
import ujson as json
import keplerphone

DEBUG = True

# construct application object
app = flask.Flask(__name__)
app.config.from_object(__name__)


def load_config(server_ini):
    P = ConfigParser.RawConfigParser()

    P.opionxform = str
    P.read(server_ini)

    CFG = {}
    for section in P.sections():
        CFG[section] = dict(P.items(section))

    for (k, v) in CFG['server'].iteritems():
        app.config[k] = v
    return CFG


def run(**kwargs):
    app.run(**kwargs)


@app.route('/keplerphone/<int:kic>/<scale>/<speed>')
def make_music(kic, scale, speed):

    speed = float(speed)
    return flask.send_file(keplerphone.make_music(kic, scale=scale, speed=speed),
                           mimetype='audio/x-midi')


@app.route('/img/<int:kic>')
def make_img(kic):
    return flask.send_file(keplerphone.make_image(kic), mimetype='image/x-png')


@app.route('/scales')
def get_scales():
    return json.encode(keplerphone.get_scales())<commit_msg>added filename to downloads<commit_after>#!/usr/bin/env python

import argparse
import flask
import ConfigParser
import mimetypes
import os
import re
import sys
import ujson as json
import keplerphone

DEBUG = True

# construct application object
app = flask.Flask(__name__)
app.config.from_object(__name__)


def load_config(server_ini):
    P = ConfigParser.RawConfigParser()

    P.opionxform = str
    P.read(server_ini)

    CFG = {}
    for section in P.sections():
        CFG[section] = dict(P.items(section))

    for (k, v) in CFG['server'].iteritems():
        app.config[k] = v
    return CFG


def run(**kwargs):
    app.run(**kwargs)


@app.route('/keplerphone/<int:kic>/<scale>/<speed>')
def make_music(kic, scale, speed):

    speed = float(speed)
    midi_file = keplerphone.make_music(kic, scale=scale, speed=speed)

    return flask.send_file(midi_file, as_attachment=True,
                           attachment_filename=os.path.basename(midi_file),
                           mimetype='audio/x-midi')


@app.route('/img/<int:kic>')
def make_img(kic):
    return flask.send_file(keplerphone.make_image(kic), mimetype='image/x-png')


@app.route('/scales')
def get_scales():
    return json.encode(keplerphone.get_scales())
{'fraction_non_alphanumeric': 0.13432835820895522, 'fraction_numerical': 0.0, 'mean_word_length': 3.6640159045725644, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6553690', 'n_tokens_mistral': 839, 'n_tokens_neox': 788, 'n_words': 164}