mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 00:02:28 +00:00
Implementing the evaluation service inside the Senpy api
This commit is contained in:
parent
551a5cb176
commit
67bae9a20d
15
senpy/api.py
15
senpy/api.py
@ -53,6 +53,21 @@ API_PARAMS = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EVAL_PARAMS = {
|
||||||
|
"algorithm": {
|
||||||
|
"aliases": ["plug", "p", "plugins", "algorithms", 'algo', 'a', 'plugin'],
|
||||||
|
"description": "Plugins to be evaluated",
|
||||||
|
"required": True,
|
||||||
|
"help": "See activated plugins in /plugins"
|
||||||
|
},
|
||||||
|
"dataset": {
|
||||||
|
"aliases": ["datasets", "data", "d"],
|
||||||
|
"description": "Datasets to be evaluated",
|
||||||
|
"required": True,
|
||||||
|
"help": "See avalaible datasets in /datasets"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PLUGINS_PARAMS = {
|
PLUGINS_PARAMS = {
|
||||||
"plugin_type": {
|
"plugin_type": {
|
||||||
"@id": "pluginType",
|
"@id": "pluginType",
|
||||||
|
@ -19,7 +19,7 @@ Blueprints for Senpy
|
|||||||
"""
|
"""
|
||||||
from flask import (Blueprint, request, current_app, render_template, url_for,
|
from flask import (Blueprint, request, current_app, render_template, url_for,
|
||||||
jsonify)
|
jsonify)
|
||||||
from .models import Error, Response, Help, Plugins, read_schema
|
from .models import Error, Response, Help, Plugins, read_schema, Datasets
|
||||||
from . import api
|
from . import api
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
@ -133,6 +133,17 @@ def api_root():
|
|||||||
req = api.parse_call(request.parameters)
|
req = api.parse_call(request.parameters)
|
||||||
return current_app.senpy.analyse(req)
|
return current_app.senpy.analyse(req)
|
||||||
|
|
||||||
|
@api_blueprint.route('/evaluate/', methods=['POST', 'GET'])
|
||||||
|
@basic_api
|
||||||
|
def evaluate():
|
||||||
|
if request.parameters['help']:
|
||||||
|
dic = dict(api.EVAL_PARAMS)
|
||||||
|
response = Help(parameters=dic)
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
params = api.parse_params(request.parameters, api.EVAL_PARAMS)
|
||||||
|
response = current_app.senpy.evaluate(params)
|
||||||
|
return response
|
||||||
|
|
||||||
@api_blueprint.route('/plugins/', methods=['POST', 'GET'])
|
@api_blueprint.route('/plugins/', methods=['POST', 'GET'])
|
||||||
@basic_api
|
@basic_api
|
||||||
@ -150,3 +161,12 @@ def plugins():
|
|||||||
def plugin(plugin=None):
|
def plugin(plugin=None):
|
||||||
sp = current_app.senpy
|
sp = current_app.senpy
|
||||||
return sp.get_plugin(plugin)
|
return sp.get_plugin(plugin)
|
||||||
|
|
||||||
|
|
||||||
|
@api_blueprint.route('/datasets/', methods=['POST','GET'])
|
||||||
|
@basic_api
|
||||||
|
def datasets():
|
||||||
|
sp = current_app.senpy
|
||||||
|
datasets = sp.datasets
|
||||||
|
dic = Datasets(datasets = list(datasets.values()))
|
||||||
|
return dic
|
@ -12,10 +12,17 @@ class Client(object):
|
|||||||
def analyse(self, input, method='GET', **kwargs):
|
def analyse(self, input, method='GET', **kwargs):
|
||||||
return self.request('/', method=method, input=input, **kwargs)
|
return self.request('/', method=method, input=input, **kwargs)
|
||||||
|
|
||||||
|
def evaluate(self, input, method='GET', **kwargs):
|
||||||
|
return self.request('/evaluate', method = method, input=input, **kwargs)
|
||||||
|
|
||||||
def plugins(self, *args, **kwargs):
|
def plugins(self, *args, **kwargs):
|
||||||
resp = self.request(path='/plugins').plugins
|
resp = self.request(path='/plugins').plugins
|
||||||
return {p.name: p for p in resp}
|
return {p.name: p for p in resp}
|
||||||
|
|
||||||
|
def datasets(self):
|
||||||
|
resp = self.request(path='/datasets').datasets
|
||||||
|
return {d.name: d for d in resp}
|
||||||
|
|
||||||
def request(self, path=None, method='GET', **params):
|
def request(self, path=None, method='GET', **params):
|
||||||
url = '{}{}'.format(self.endpoint, path)
|
url = '{}{}'.format(self.endpoint, path)
|
||||||
response = requests.request(method=method, url=url, params=params)
|
response = requests.request(method=method, url=url, params=params)
|
||||||
|
Loading…
Reference in New Issue
Block a user