Dmitry Trifonov commited on
Commit
bf413b8
·
1 Parent(s): aeb505f

clean up code

Browse files
Files changed (1) hide show
  1. text_to_image.py +9 -13
text_to_image.py CHANGED
@@ -128,11 +128,6 @@ def start_inference_server(fc: FairClient):
128
  detach=True)
129
 
130
 
131
- def start_services(fc):
132
- start_tunnel(fc)
133
- start_inference_server(fc)
134
-
135
-
136
  def text_to_image(text):
137
  global endpoint_client
138
  global fair_client
@@ -140,18 +135,19 @@ def text_to_image(text):
140
  fair_client = create_fair_client()
141
 
142
  try:
143
- if endpoint_client is None: # try connecting to the server
144
- endpoint_client = create_endpoint_client(fair_client, 1)
145
- else: # try inference
146
  return endpoint_client.infer(text)
 
 
 
147
  except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout):
148
- endpoint_client = None
149
-
150
- # start all services
151
- if endpoint_client is None:
152
- start_services(fair_client)
153
  endpoint_client = create_endpoint_client(fair_client, retries=10)
154
 
 
155
  return endpoint_client.infer(text)
156
 
157
 
 
128
  detach=True)
129
 
130
 
 
 
 
 
 
131
  def text_to_image(text):
132
  global endpoint_client
133
  global fair_client
 
135
  fair_client = create_fair_client()
136
 
137
  try:
138
+ # client is configured, try to do inference right away
139
+ if endpoint_client is not None:
 
140
  return endpoint_client.infer(text)
141
+ # client is not configured, try connecting to the inference server, maybe it is running
142
+ else:
143
+ endpoint_client = create_endpoint_client(fair_client, 1)
144
  except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, requests.exceptions.Timeout):
145
+ # inference server is not ready, start inference server and open the tunnel
146
+ start_inference_server(fair_client)
147
+ start_tunnel(fair_client)
 
 
148
  endpoint_client = create_endpoint_client(fair_client, retries=10)
149
 
150
+ # run inference
151
  return endpoint_client.infer(text)
152
 
153