Esempio n. 1
0
 def __init__(self,
              session_provider: SessionProvider,
              entity_class: Type,
              logger: Optional[Logger] = None) -> None:
     self.session_provider = session_provider
     self.entity_class = entity_class
     self.logger = logger or get_logger()
Esempio n. 2
0
 def __init__(self,
              vamp_interface: Any = vamp,
              vamp_host_interface: Any = vampyhost,
              plugin_black_list: Optional[List[str]] = None,
              logger: Optional[Logger] = None) -> None:
     self.vamp_interface = vamp_interface
     self.vamp_host_interface = vamp_host_interface
     self.black_list_plugin_key = plugin_black_list or []
     self.logger = logger or get_logger()
Esempio n. 3
0
def extract_feature(extraction_request: Dict[str, Any]) -> Dict[str, Any]:
    logger = get_logger()
    request = ExtractionRequest.from_serializable(extraction_request)

    plugin_provider = VampyPluginProvider(plugin_black_list=[], logger=logger)
    mp3_file_store = Mp3FileStore(AUDIO_FILES_DIR)

    db_session_provider = SessionProvider()
    audio_tag_repo = AudioTagRepository(db_session_provider)
    audio_meta_repo = AudioFileRepository(db_session_provider)
    plugin_repo = VampyPluginRepository(db_session_provider)
    plugin_config_repo = PluginConfigRepository(db_session_provider)
    feature_data_repo = FeatureDataRepository(db_session_provider)
    feature_meta_repo = FeatureMetaRepository(db_session_provider)
    metric_definition_repo = MetricDefinitionRepository(
        db_session_provider, plugin_repo)
    metric_value_repo = MetricValueRepository(db_session_provider,
                                              metric_definition_repo)
    result_repo = RequestRepository(db_session_provider, audio_meta_repo,
                                    audio_tag_repo, plugin_repo,
                                    plugin_config_repo)
    result_stats_repo = ResultStatsRepository(db_session_provider)

    extraction_service = FeatureExtractionService(
        plugin_provider=plugin_provider,
        audio_file_store=mp3_file_store,
        audio_tag_repo=audio_tag_repo,
        audio_meta_repo=audio_meta_repo,
        plugin_repo=plugin_repo,
        plugin_config_repo=plugin_config_repo,
        metric_definition_repo=metric_definition_repo,
        metric_value_repo=metric_value_repo,
        feature_data_repo=feature_data_repo,
        feature_meta_repo=feature_meta_repo,
        request_repo=result_repo,
        result_stats_repo=result_stats_repo,
        logger=logger)
    try:
        extraction_service.extract_feature_and_store(request)
        return extraction_request
    except SoftTimeLimitExceeded as e:
        logger.exception(e)
        raise e
Esempio n. 4
0
def main():
    setup_logger()
    logger = get_logger()
    logger.info("Initializing Coordinator app...")
    create_db_tables(only_if_absent=True)
    start_app(logger, "0.0.0.0", 8080)
Esempio n. 5
0
from flask import jsonify, make_response, Request

from audiopyle.lib.abstractions.api_model import ApiRequest, ApiResponse, HttpMethod
from audiopyle.lib.utils.conversion import seconds_between
from audiopyle.lib.utils.logger import get_logger

logger = get_logger()

COORDINATOR_STATUS_RESPONSE = "ok"


def build_response(the_response: ApiResponse) -> str:
    return make_response(jsonify(the_response.payload) if the_response.payload is not None else '',
                         the_response.status_code.value, the_response.headers or {})


def build_request(flask_request: Request, **kwargs) -> ApiRequest:
    return ApiRequest(url=flask_request.full_path, method=HttpMethod(flask_request.method), query_params=kwargs,
                      headers=flask_request.headers, payload=flask_request.json or {})


def log_api_call(api_request: ApiRequest, api_response: ApiResponse) -> None:
    serving_time = seconds_between(api_request.creation_time)
    logger.info("Served {} @ {} with {} ({} -> {}) in {}s.".format(api_request.method,
                                                                   api_request.url,
                                                                   api_response.status_code,
                                                                   api_request.size_humanized(),
                                                                   api_response.size_humanized(),
                                                                   serving_time))
Esempio n. 6
0
 def __init__(self,
              base_dir: str,
              permissions: int = DEFAULT_FILE_PERMISSIONS) -> None:
     self.base_dir = base_dir
     self.permissions = permissions
     self.logger = get_logger()