unitypredict 1.1.56__tar.gz → 1.1.58__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitypredict
3
- Version: 1.1.56
3
+ Version: 1.1.58
4
4
  Summary:
5
5
  Home-page: https://unitypredict.com
6
6
  Author: UnityPredict
@@ -6,6 +6,13 @@ import time
6
6
 
7
7
  import requests
8
8
 
9
+
10
+
11
+ class LocalFile:
12
+ fileName: str = ''
13
+ def __init__(self, fileName: str):
14
+ self.fileName = fileName
15
+
9
16
  class UnityPredictFileTransmitDto:
10
17
 
11
18
  """
@@ -101,6 +108,7 @@ class UnityPredictClient:
101
108
  ApiBaseUrl: str = 'https://api.prod.unitypredict.com/api'
102
109
  ApiMaxTimeout: int = 12 * 60 * 60
103
110
 
111
+
104
112
  def __init__(self, apiKey, apiMaxTimeoutInSec = 12 * 60 * 60):
105
113
 
106
114
  """
@@ -115,6 +123,7 @@ class UnityPredictClient:
115
123
 
116
124
 
117
125
 
126
+
118
127
  def _uploadFileAndStartPredict(self, modelId: str, request: UnityPredictRequest):
119
128
 
120
129
  apiKey = self.ApiKey
@@ -128,7 +137,7 @@ class UnityPredictClient:
128
137
  #####
129
138
  # first get a list of file that we'll need to upload later & update the POST obj
130
139
  for xvarName in request.InputValues:
131
- if isinstance(request.InputValues.get(xvarName), UnityPredictFileTransmitDto):
140
+ if isinstance(request.InputValues.get(xvarName), LocalFile):
132
141
  needFileUpload = True
133
142
  break
134
143
 
@@ -164,10 +173,14 @@ class UnityPredictClient:
164
173
 
165
174
  # upload the files
166
175
  for xvarName in request.InputValues:
167
- if isinstance(request.InputValues.get(xvarName), UnityPredictFileTransmitDto):
168
- fileToUpload: UnityPredictFileTransmitDto = request.InputValues.get(xvarName)
176
+ if isinstance(request.InputValues.get(xvarName), LocalFile):
177
+ fileName = request.InputValues.get(xvarName).fileName
178
+ if not os.path.exists(fileName):
179
+ results.ErrorMessages = f"File {fileName} does not exist!"
180
+ return (results, {})
181
+ fileToUpload: UnityPredictFileTransmitDto = UnityPredictFileTransmitDto(fileName, open(fileName, 'rb'))
169
182
  print (f"Uploading {fileToUpload.FileName}...")
170
- response = requests.get(url = "{}/predict/upload/{}/{}".format(apiBaseUrl, requestId, fileToUpload.FileName), headers={"Authorization": "Bearer {}".format(apiKey)})
183
+ response = requests.get(url = "{}/predict/upload/{}/{}".format(apiBaseUrl, requestId, os.path.basename(fileToUpload.FileName)), headers={"Authorization": "Bearer {}".format(apiKey)})
171
184
  if response.status_code != 200:
172
185
  results.ErrorMessages = 'Error from server: {}'.format(response.status_code)
173
186
  return (results, {})
@@ -287,7 +300,7 @@ class UnityPredictClient:
287
300
  if (finalResponseJson.get('status') == 'Processing'):
288
301
  statusUrl = finalResponseJson.get('statusUrl') # this is probably a long-running inference
289
302
 
290
- loopCount = 0
303
+ loopWaitTime = 0.25
291
304
  startTime = time.time()
292
305
  maxPredictTime = self.ApiMaxTimeout
293
306
  maxTimeExceed = False
@@ -302,10 +315,10 @@ class UnityPredictClient:
302
315
  response = requests.get(url = statusUrl, headers={"Authorization": "Bearer {}".format(apiKey)})
303
316
  finalResponseJson = response.json()
304
317
 
305
- delay = min(loopCount * 2, 30)
318
+ delay = min(loopWaitTime, 30)
306
319
  time.sleep(delay)
307
320
 
308
- loopCount = loopCount + 1
321
+ loopWaitTime *= 2
309
322
 
310
323
  print('Waiting {} seconds for job to finish...'.format(delay))
311
324
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitypredict
3
- Version: 1.1.56
3
+ Version: 1.1.58
4
4
  Summary:
5
5
  Home-page: https://unitypredict.com
6
6
  Author: UnityPredict
File without changes
File without changes
File without changes