<commit_before># -*- coding: utf-8 -*-
#!/usr/bin/env python

"""
Simple restfull service providing sound recognition to remote
"""

from flask import Flask
from flask_restful import Api, reqparse, Resource
from flask_restful import fields, marshal_with
from flask.ext.sqlalchemy import SQLAlchemy
from resources.sound_file import SendSoundFile
from resources.classify_sounds import ClassifySoundApi
import argparse

from sound_classification.classification_service import SoundClassification

import os

app = Flask(__name__)
_basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+ os.path.join(_basedir, 'app.db')

db = SQLAlchemy(app)

class SoundFile(db.Model):
    __tablename__ = 'mysound'
    id = db.Column(db.INTEGER, primary_key=True)
    filename = db.Column(db.Text)
    content_classification = db.Column(db.Text)
    device_type = db.Column(db.Text)
    mimetype = db.Column(db.Text)

    def __init__(self, filename="default", content_class="default", device_type=None, mimetype=None):
        self.filename = filename
        self.content_classification = content_class
        self.device_type = device_type
        self.mimetype = mimetype

    def __repr__(self):
        return "Id: {}, content class: {}, data file: {}".format(self.id, self.content_classification, self.audio_file)

db.create_all()
api = Api(app)

api.add_resource(SendSoundFile, '/api/SendSoundFile', '/api/SendSoundFile<id>', resource_class_kwargs={'db_session':db.session})
api.add_resource(ClassifySoundApi, '/api/ClassifySoundFile', '/api/ClassifiySoundFile<id>', resource_class_kwargs={'db_session':db.session, 'api':api})

if __name__ == '__main__':
    usage = "python api.py -p '/media/dataset/*.wav'"
    parser = argparse.ArgumentParser(description="usage is %s" % usage)
    parser.add_argument('--wav-file-pattern', '-p', type=str, default="'/media/dataset/*.wav'")
    args = parser.parse_args()

    print("args is %s" % args)
    api.sound_classification_obj = SoundClassification(wav_file_list=args.wav_file_pattern)
    api.sound_classification_obj.learn()

    app.run(debug=True, host='0.0.0.0')<commit_msg>updating list of arguments for running app<commit_after># -*- coding: utf-8 -*-
#!/usr/bin/env python

"""
Simple restfull service providing sound recognition to remote
"""

from flask import Flask
from flask_restful import Api, reqparse, Resource
from flask_restful import fields, marshal_with
from flask.ext.sqlalchemy import SQLAlchemy
from resources.sound_file import SendSoundFile
from resources.classify_sounds import ClassifySoundApi
import argparse

from sound_classification.classification_service import SoundClassification

import os

app = Flask(__name__)
_basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+ os.path.join(_basedir, 'app.db')

db = SQLAlchemy(app)

class SoundFile(db.Model):
    __tablename__ = 'mysound'
    id = db.Column(db.INTEGER, primary_key=True)
    filename = db.Column(db.Text)
    content_classification = db.Column(db.Text)
    device_type = db.Column(db.Text)
    mimetype = db.Column(db.Text)

    def __init__(self, filename="default", content_class="default", device_type=None, mimetype=None):
        self.filename = filename
        self.content_classification = content_class
        self.device_type = device_type
        self.mimetype = mimetype

    def __repr__(self):
        return "Id: {}, content class: {}, data file: {}".format(self.id, self.content_classification, self.audio_file)

db.create_all()
api = Api(app)

api.add_resource(SendSoundFile, '/api/SendSoundFile', '/api/SendSoundFile<id>', resource_class_kwargs={'db_session':db.session})
api.add_resource(ClassifySoundApi, '/api/ClassifySoundFile', '/api/ClassifiySoundFile<id>', resource_class_kwargs={'db_session':db.session, 'api':api})

if __name__ == '__main__':
    usage = "python api.py -p '/media/dataset/*.wav'"
    parser = argparse.ArgumentParser(description="usage is %s" % usage)
    parser.add_argument('--wav-files', '-w', type=str, required=True, nargs='+')
    args = parser.parse_args()

    print("args is %s" % args)
    api.sound_classification_obj = SoundClassification(wav_file_list=args.wav_files)
    api.sound_classification_obj.learn()

    app.run(debug=True, host='0.0.0.0')
{'fraction_non_alphanumeric': 0.13107578898871228, 'fraction_numerical': 0.00230361667818475, 'mean_word_length': 4.923601637107776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7357199', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1402, 'n_words': 282}