Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

relaxml.py 1.7 KB

You have to be logged in to leave a comment. Sign In
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
  1. import logging
  2. import os
  3. import requests
  4. from label_studio_tools.core.label_config import parse_config
  5. from requests.auth import HTTPBasicAuth
  6. from typing import List
  7. from .datamodel import Setup, Task
  8. from .utils import uri_to_url, download_url
  9. class RelaxML:
  10. def __init__(self):
  11. '''Good place to load your model and setup variables'''
  12. self.project = None
  13. self.schema = None
  14. self.hostname = None
  15. self.access_token = None
  16. self.user = os.getenv("DAGSHUB_USER_NAME")
  17. self.token = os.getenv("DAGSHUB_TOKEN")
  18. self.repo = os.getenv("DAGSHUB_REPO_NAME")
  19. self.owner = os.getenv("DAGSHUB_REPO_OWNER")
  20. # HERE: Load model
  21. def setup(self, setup: Setup):
  22. '''Store the setup information sent by Label Studio to the ML backend'''
  23. self.project = setup.project
  24. self.parsed_label_config = parse_config(setup.label_schema)
  25. self.hostname = setup.hostname
  26. self.access_token = setup.access_token
  27. from_name, schema = list(self.parsed_label_config.items())[0]
  28. self.from_name = from_name
  29. self.to_name = schema['to_name'][0]
  30. self.labels = schema['labels']
  31. def send_predictions(self, result):
  32. '''Send prediction results to Label Studio'''
  33. url = f'https://dagshub.com/{self.owner}/{self.repo}/annotations/git/api/predictions/'
  34. auth = HTTPBasicAuth(self.user, self.token)
  35. res = requests.post(url, auth=auth, json=result)
  36. if res.status_code != 200:
  37. logging.warning(res)
  38. def predict(self, tasks: List[Task]):
  39. '''Add predict logic here and call `send_predictions` for each task'''
  40. pass
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...