selfitcamera commited on
Commit
bf92994
1 Parent(s): 2375767
Files changed (2) hide show
  1. app.py +21 -11
  2. utils.py +2 -1
app.py CHANGED
@@ -85,23 +85,29 @@ def onLoad(request: gr.Request):
85
  if x_forwarded_for:
86
  client_ip = x_forwarded_for
87
  his_datas = [None for _ in range(10)]
 
88
  try:
89
  infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
90
  print(client_ip, 'history infs: ', len(infs))
91
- # print(infs)
92
-
93
  for i, inf in enumerate(infs):
94
- if i>4: continue
95
- pose = inf['pose']
96
- res = inf['res']
97
- # his_datas[i*2] = f"[pose]({pose})"+f"![pose]({pose})"
98
- # his_datas[i*2+1] = f"[res]({res})"+f"![res]({res})"
99
- his_datas[i*2] = f"<img src=\"{pose}\" >"
100
- his_datas[i*2+1] = f"<img src=\"{res}\" >"
101
-
 
 
 
 
102
  time.sleep(3)
103
  except Exception as e:
104
  print(e)
 
105
  return his_datas
106
 
107
 
@@ -145,6 +151,10 @@ with gr.Blocks(css=css) as demo:
145
  label='runtime information')
146
 
147
  with gr.Tab('history'):
 
 
 
 
148
  with gr.Row():
149
  his_pose_image1 = gr.HTML()
150
  his_res_image1 = gr.HTML()
@@ -172,7 +182,7 @@ with gr.Blocks(css=css) as demo:
172
  demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
173
  his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
174
  his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
175
- ])
176
 
177
  if __name__ == "__main__":
178
 
 
85
  if x_forwarded_for:
86
  client_ip = x_forwarded_for
87
  his_datas = [None for _ in range(10)]
88
+ info = ''
89
  try:
90
  infs = getAllInfs(ApiUrl, OpenId, ApiKey, client_ip)
91
  print(client_ip, 'history infs: ', len(infs))
92
+ cnt = 0
93
+ finish_n, fail_n, queue_n = 0, 0, 0
94
  for i, inf in enumerate(infs):
95
+ if inf['state']==2:
96
+ if cnt>4: continue
97
+ pose, res = inf['pose'], inf['res']
98
+ his_datas[cnt*2] = f"<img src=\"{pose}\" >"
99
+ his_datas[cnt*2+1] = f"<img src=\"{res}\" >"
100
+ finish_n += 1
101
+ cnt += 1
102
+ elif inf['state'] in [-1, -2, 0]:
103
+ fail_n += 1
104
+ elif inf['state'] in [1]:
105
+ queue_n += 1
106
+ info = f"you have {finish_n} successed tasks, {queue_n} running tasks, {fail_n} failed tasks"
107
  time.sleep(3)
108
  except Exception as e:
109
  print(e)
110
+ his_datas = his_datas + [info]
111
  return his_datas
112
 
113
 
 
151
  label='runtime information')
152
 
153
  with gr.Tab('history'):
154
+
155
+ with gr.Row():
156
+ MK02 = gr.Markdown()
157
+
158
  with gr.Row():
159
  his_pose_image1 = gr.HTML()
160
  his_res_image1 = gr.HTML()
 
182
  demo.load(onLoad, inputs=[], outputs=[his_pose_image1, his_res_image1,
183
  his_pose_image2, his_res_image2, his_pose_image3, his_res_image3,
184
  his_pose_image4, his_res_image4, his_pose_image5, his_res_image5,
185
+ MK02])
186
 
187
  if __name__ == "__main__":
188
 
utils.py CHANGED
@@ -57,7 +57,8 @@ def getAllInfs(apiUrl, openId, apiKey, clientIp):
57
  records = ret.json()['data']['records']
58
  for record in records:
59
  res.append({'pose':OssUrl+record['body_url']+"?thumbnail/768x768>",
60
- 'res':OssUrl+record['showUrl']+"?thumbnail/768x768>"})
 
61
  # res.append({'pose':OssUrl+record['body_url'],
62
  # 'res':OssUrl+record['showUrl']})
63
  return res
 
57
  records = ret.json()['data']['records']
58
  for record in records:
59
  res.append({'pose':OssUrl+record['body_url']+"?thumbnail/768x768>",
60
+ 'res':OssUrl+record['showUrl']+"?thumbnail/768x768>",
61
+ 'state':int(record['state'])})
62
  # res.append({'pose':OssUrl+record['body_url'],
63
  # 'res':OssUrl+record['showUrl']})
64
  return res