Spaces:
Sleeping
Sleeping
Dmitry Trifonov
commited on
Commit
·
3e7cff9
1
Parent(s):
2e91066
fix demo for Fair 0.15
Browse files
fair.py
CHANGED
@@ -8,9 +8,10 @@ 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 |
class FairApiClient:
|
16 |
def __init__(self, server_address: str):
|
@@ -62,12 +63,14 @@ class FairApiClient:
|
|
62 |
return int(response.text)
|
63 |
|
64 |
def put_job(self, program_id, input_files, output_files):
|
65 |
-
url = f"{self.server_address}/jobs
|
66 |
data = {
|
|
|
|
|
67 |
'input_files': input_files,
|
68 |
-
'output_files': output_files
|
|
|
69 |
}
|
70 |
-
|
71 |
response = self.put(url=url, data=data)
|
72 |
|
73 |
return int(response.text)
|
@@ -93,7 +96,6 @@ class FairApiClient:
|
|
93 |
response = self.put(url=url, data=None)
|
94 |
return response.text
|
95 |
|
96 |
-
|
97 |
def wait_for_file(self, job_id, path, attempts=10) -> BinaryIO:
|
98 |
headers = {
|
99 |
'Authorization': f'Bearer {self.token}'
|
@@ -119,8 +121,9 @@ class FairApiClient:
|
|
119 |
|
120 |
|
121 |
def text_to_image(text):
|
122 |
-
|
123 |
-
|
|
|
124 |
client = FairApiClient(SERVER_ADRESS)
|
125 |
client.authenticate(email=email, password=password)
|
126 |
|
|
|
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 |
|
16 |
class FairApiClient:
|
17 |
def __init__(self, server_address: str):
|
|
|
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,
|
73 |
}
|
|
|
74 |
response = self.put(url=url, data=data)
|
75 |
|
76 |
return int(response.text)
|
|
|
96 |
response = self.put(url=url, data=None)
|
97 |
return response.text
|
98 |
|
|
|
99 |
def wait_for_file(self, job_id, path, attempts=10) -> BinaryIO:
|
100 |
headers = {
|
101 |
'Authorization': f'Bearer {self.token}'
|
|
|
121 |
|
122 |
|
123 |
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 |
|