forked from HumanSignal/label-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serializers.py
29 lines (25 loc) · 1.49 KB
/
serializers.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
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
from rest_framework import serializers
from ml.models import MLBackend
class MLBackendSerializer(serializers.ModelSerializer):
def validate(self, attrs):
attrs = super(MLBackendSerializer, self).validate(attrs)
url = attrs['url']
if MLBackend.healthcheck_(url).is_error:
raise serializers.ValidationError("Can't connect to ML backend {url}, health check failed. "
f'Make sure it is up and your firewall is properly configured. '
f'<a href="https://labelstud.io/guide/ml.html>Learn more</a>'
f' about how to set up an ML backend.')
project = attrs['project']
setup_response = MLBackend.setup_(url, project)
if setup_response.is_error:
raise serializers.ValidationError(
f"Successfully connected to {url} but it doesn't look like a valid ML backend. "
f'Reason: {setup_response.error_message}.\n'
f'Check the ML backend server console logs to check the status. There might be\n'
f'something wrong with your model or it might be incompatible with the current labeling configuration.')
return attrs
class Meta:
model = MLBackend
fields = '__all__'