Dmitry Trifonov commited on
Commit
04f1dbd
·
1 Parent(s): 3e7cff9

fix demo for Fair 0.16

Browse files
Files changed (1) hide show
  1. fair.py +14 -27
fair.py CHANGED
@@ -8,8 +8,8 @@ logger = logging.getLogger()
8
  import requests
9
  import tempfile
10
 
11
- SERVER_ADRESS = "https://faircompute.com:8000/api/v1"
12
- # SERVER_ADRESS = "http://localhost:8000/api/v1"
13
  DOCKER_IMAGE = "faircompute/stable-diffusion:pytorch-1.13.1-cu116"
14
 
15
 
@@ -49,24 +49,17 @@ class FairApiClient:
49
 
50
  return response
51
 
52
- def put_program(self, launcher: str, image: str, runtime: str, command: List[str]):
53
- url = f"{self.server_address}/programs"
54
- data = {
55
- launcher: {
56
- "image": image,
57
- "command": command,
58
- "runtime": runtime
59
- }
60
- }
61
- response = self.put(url=url, data=data)
62
-
63
- return int(response.text)
64
-
65
- def put_job(self, program_id, input_files, output_files):
66
  url = f"{self.server_address}/jobs"
67
  data = {
68
- 'type': 'V015',
69
- 'program': program_id,
 
 
 
 
 
 
70
  'input_files': input_files,
71
  'output_files': output_files,
72
  'target_node': None,
@@ -124,18 +117,12 @@ def text_to_image(text):
124
  # default credentials will work only for local server built in debug mode
125
  email = os.getenv('FAIRCOMPUTE_EMAIL', "debug-email")
126
  password = os.environ.get('FAIRCOMPUTE_PASSWORD', "debug-pwd")
127
- client = FairApiClient(SERVER_ADRESS)
128
  client.authenticate(email=email, password=password)
129
 
130
- program_id = client.put_program(
131
- launcher="Docker",
132
- image=DOCKER_IMAGE,
133
- runtime="nvidia",
134
- command=[])
135
- logger.info(program_id)
136
-
137
  job_id = client.put_job(
138
- program_id=program_id,
 
139
  input_files=[],
140
  output_files=["/workspace/result.png"])
141
 
 
8
  import requests
9
  import tempfile
10
 
11
+ SERVER_ADDRESS = "https://faircompute.com:8000/api/v1"
12
+ # SERVER_ADDRESS = "http://localhost:8000/api/v1"
13
  DOCKER_IMAGE = "faircompute/stable-diffusion:pytorch-1.13.1-cu116"
14
 
15
 
 
49
 
50
  return response
51
 
52
+ def put_job(self, image: str, command: List[str], input_files, output_files):
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  url = f"{self.server_address}/jobs"
54
  data = {
55
+ 'type': 'V016',
56
+ 'container_desc': {
57
+ 'type': 'V016',
58
+ 'image': image,
59
+ 'runtime': 'nvidia',
60
+ 'ports': [],
61
+ 'command': command,
62
+ },
63
  'input_files': input_files,
64
  'output_files': output_files,
65
  'target_node': None,
 
117
  # default credentials will work only for local server built in debug mode
118
  email = os.getenv('FAIRCOMPUTE_EMAIL', "debug-email")
119
  password = os.environ.get('FAIRCOMPUTE_PASSWORD', "debug-pwd")
120
+ client = FairApiClient(SERVER_ADDRESS)
121
  client.authenticate(email=email, password=password)
122
 
 
 
 
 
 
 
 
123
  job_id = client.put_job(
124
+ image=DOCKER_IMAGE,
125
+ command=[],
126
  input_files=[],
127
  output_files=["/workspace/result.png"])
128