Spaces:
Runtime error
Runtime error
chenjian
commited on
Commit
·
67e702f
1
Parent(s):
5d4a3a1
fix
Browse files
ernie_vilg/__pycache__/module.cpython-37.pyc
CHANGED
|
Binary files a/ernie_vilg/__pycache__/module.cpython-37.pyc and b/ernie_vilg/__pycache__/module.cpython-37.pyc differ
|
|
|
ernie_vilg/module.py
CHANGED
|
@@ -118,11 +118,36 @@ class ErnieVilG:
|
|
| 118 |
print('task poll start time', time.ctime(start_time))
|
| 119 |
process_bar = tqdm(total=100, unit='%')
|
| 120 |
results = {}
|
| 121 |
-
|
|
|
|
| 122 |
while True:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
if not taskids:
|
| 124 |
break
|
| 125 |
-
total_time = 0
|
| 126 |
has_done = []
|
| 127 |
for taskid in taskids:
|
| 128 |
res = requests.post(get_url, headers={'Content-Type':'application/x-www-form-urlencoded'}, data={'access_token': token,'taskId': {taskid}})
|
|
@@ -148,26 +173,16 @@ class ErnieVilG:
|
|
| 148 |
raise RuntimeError("Token失效重新请求后依然发生错误,请检查输入的参数")
|
| 149 |
if res['msg'] == 'success':
|
| 150 |
if res['data']['status'] == 1:
|
|
|
|
| 151 |
has_done.append(res['data']['taskId'])
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
else:
|
| 158 |
print(res['msg'])
|
| 159 |
raise RuntimeError(res['msg'])
|
| 160 |
-
total_time = int(re.match('[0-9]+', str(res['data']['waiting'])).group(0)) * 60
|
| 161 |
-
end_time = time.time()
|
| 162 |
-
progress_rate = int(((end_time - start_time) / total_time*100)) if total_time != 0 else 100
|
| 163 |
-
if progress_rate > process_bar.n:
|
| 164 |
-
increase_rate = progress_rate - process_bar.n
|
| 165 |
-
if progress_rate >= 100:
|
| 166 |
-
increase_rate = 100 - process_bar.n
|
| 167 |
-
else:
|
| 168 |
-
increase_rate = 0
|
| 169 |
-
process_bar.update(increase_rate)
|
| 170 |
-
time.sleep(5)
|
| 171 |
for taskid in has_done:
|
| 172 |
taskids.remove(taskid)
|
| 173 |
end_time = time.time() #debug code
|
|
|
|
| 118 |
print('task poll start time', time.ctime(start_time))
|
| 119 |
process_bar = tqdm(total=100, unit='%')
|
| 120 |
results = {}
|
| 121 |
+
total_time = 60 * len(taskids)
|
| 122 |
+
|
| 123 |
while True:
|
| 124 |
+
end_time = time.time()
|
| 125 |
+
duration = end_time - start_time
|
| 126 |
+
progress_rate = int((duration) / total_time*100)
|
| 127 |
+
if not taskids:
|
| 128 |
+
progress_rate = 100
|
| 129 |
+
if progress_rate > process_bar.n:
|
| 130 |
+
if progress_rate >= 100:
|
| 131 |
+
if not taskids:
|
| 132 |
+
increase_rate = 100 - process_bar.n
|
| 133 |
+
else:
|
| 134 |
+
increase_rate = 0
|
| 135 |
+
else:
|
| 136 |
+
increase_rate = progress_rate - process_bar.n
|
| 137 |
+
else:
|
| 138 |
+
increase_rate = 0
|
| 139 |
+
process_bar.update(increase_rate)
|
| 140 |
+
if duration < 30:
|
| 141 |
+
time.sleep(5)
|
| 142 |
+
print('increase_time', end_time - start_time)
|
| 143 |
+
print('increase_rate', increase_rate, flush=True)
|
| 144 |
+
continue
|
| 145 |
+
else:
|
| 146 |
+
time.sleep(1)
|
| 147 |
+
print('increase_time', end_time - start_time)
|
| 148 |
+
print('increase_rate', increase_rate, flush=True)
|
| 149 |
if not taskids:
|
| 150 |
break
|
|
|
|
| 151 |
has_done = []
|
| 152 |
for taskid in taskids:
|
| 153 |
res = requests.post(get_url, headers={'Content-Type':'application/x-www-form-urlencoded'}, data={'access_token': token,'taskId': {taskid}})
|
|
|
|
| 173 |
raise RuntimeError("Token失效重新请求后依然发生错误,请检查输入的参数")
|
| 174 |
if res['msg'] == 'success':
|
| 175 |
if res['data']['status'] == 1:
|
| 176 |
+
print('I am finished', flush=True)
|
| 177 |
has_done.append(res['data']['taskId'])
|
| 178 |
+
results[res['data']['text']] = {
|
| 179 |
+
'imgUrls': res['data']['imgUrls'],
|
| 180 |
+
'waiting': res['data']['waiting'],
|
| 181 |
+
'taskId': res['data']['taskId']
|
| 182 |
+
}
|
| 183 |
else:
|
| 184 |
print(res['msg'])
|
| 185 |
raise RuntimeError(res['msg'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
for taskid in has_done:
|
| 187 |
taskids.remove(taskid)
|
| 188 |
end_time = time.time() #debug code
|