forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprecated.py
137 lines (102 loc) · 4.33 KB
/
deprecated.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
""" Deprecated APIs, they will be removed soon
"""
from label_studio.blueprint import *
class DeprecatedException(Exception):
pass
def deprecated_message(old, new):
msg = '\n! API "' + old + '" is DEPRECATED and will be removed soon, please use "' + new + '" instead!\n'
logger.warning(msg)
print(msg)
return msg
@blueprint.route('/upload/<path:path>')
@requires_auth
def deprecated_send_upload(path):
logger.warning('Task path starting with "/upload/" is deprecated and will be removed in next releases, '
'replace "/upload/" => "/data/upload/" in your tasks.json files')
project_dir = os.path.join(g.project.path, 'upload')
return open(os.path.join(project_dir, path), 'rb').read()
@blueprint.route('/api/render-label-studio', methods=['GET', 'POST'])
@requires_auth
def deprecated_api_render_label_studio():
deprecated_message('/api/render-label-studio', '/render-label-studio')
return api_render_label_studio()
@blueprint.route('/api/save-config', methods=['POST'])
@requires_auth
def deprecated_api_save_config():
deprecated_message('/api/save-config', '/api/project/config')
return api_save_config()
@blueprint.route('/api/import', methods=['POST'])
@requires_auth
def deprecated_api_import():
deprecated_message('/api/import', '/api/project/import')
return api_import()
@blueprint.route('/api/export', methods=['GET'])
@requires_auth
def deprecated_api_export():
deprecated_message('/api/export', '/api/project/export')
return api_export()
@blueprint.route('/api/projects/1/next/', methods=['GET'])
@requires_auth
def deprecated_api_generate_next_task():
deprecated_message('/api/project/1/next', '/api/project/next')
return api_generate_next_task()
@blueprint.route('/api/tasks/delete', methods=['DELETE'])
@requires_auth
def deprecated_api_tasks_delete():
deprecated_message('/api/tasks/delete', 'DELETE /api/tasks')
g.project.delete_all_tasks()
return make_response(jsonify({}), 204)
@blueprint.route('/api/projects/1/completions_ids/', methods=['GET'])
@requires_auth
def deprecated_api_all_completion_ids():
deprecated_message('/api/projects/1/completions_ids/', '/api/completions')
ids = g.project.get_completions_ids()
return make_response(jsonify(ids), 200)
@blueprint.route('/api/project/completions/', methods=['DELETE'])
@requires_auth
def deprecated_api_all_completions():
deprecated_message('/api/completions', 'DELETE /api/completions')
return api_all_completions()
@blueprint.route('/api/tasks/<task_id>/cancel', methods=['POST'])
@requires_auth
def deprecated_api_tasks_cancel(task_id):
msg = deprecated_message('/api/tasks/<task_id>/cancel', 'POST /api/tasks/<task_id>/completions/')
raise DeprecatedException(msg)
@blueprint.route('/api/projects/1/expert_instruction')
@requires_auth
def deprecated_api_instruction():
deprecated_message('/api/projects/1/expert_instruction', '/api/project')
return make_response(g.project.config['instruction'], 200)
@blueprint.route('/api/remove-ml-backend', methods=['POST'])
@requires_auth
def deprecated_api_remove_ml_backend():
deprecated_message('/api/remove-ml-backend', 'DELETE /api/models')
ml_backend_name = request.json['name']
g.project.remove_ml_backend(ml_backend_name)
return make_response(jsonify('Deleted!'), 204)
@blueprint.route('/predict', methods=['POST'])
@requires_auth
def deprecated_api_predict():
deprecated_message('/predict', '/api/models/predictions?mode=data')
if 'data' not in request.json:
task = {'data': request.json}
else:
task = request.json
if g.project.ml_backends_connected:
task_with_predictions = g.project.make_predictions(task)
return make_response(jsonify(task_with_predictions), 200)
else:
return make_response(jsonify("No ML backend"), 400)
@blueprint.route('/api/train', methods=['POST'])
@requires_auth
def deprecated_api_train():
deprecated_message('/api/train', '/api/models/train')
return api_train()
@blueprint.route('/api/project/next', methods=['GET'])
@requires_auth
def api_generate_next_task():
from label_studio.data_manager.actions import next_task
deprecated_message('/api/project/next', '/api/project/actions?id=next_task')
result = next_task(g.project, None, None)
code = result.pop('response_code', 200)
return make_response(result, code)