WeShop commited on
Commit
e27ffa6
·
1 Parent(s): 565df3e
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -26,6 +26,8 @@ agent_name = os.getenv('agent_name')
26
  app_id = os.getenv('app_id')
27
  login_status_key = os.getenv('login_status_key')
28
  login_info_key = os.getenv('login_info_key')
 
 
29
 
30
 
31
  def parse_response(response, state='default'):
@@ -243,9 +245,13 @@ def check_login_status(headers):
243
  return None, None
244
 
245
  try:
 
246
  text = headers.get(login_status_key)
247
  if not text or "." not in text:
248
- return None, None
 
 
 
249
 
250
  infos = text.split(".")
251
  if len(infos) < 2:
@@ -259,15 +265,20 @@ def check_login_status(headers):
259
  decoded_bytes = base64.b64decode(info)
260
  decoded_str = decoded_bytes.decode('utf-8')
261
  datas = json.loads(decoded_str)
262
-
263
- data = datas.get(login_info_key)
264
- if not data:
 
 
 
 
 
 
 
 
 
265
  return None, None
266
 
267
- user_id = data.get("_id")
268
- user_name = data.get("user")
269
- return user_id, user_name
270
-
271
  except Exception as e:
272
  print(f"An error occurred: {repr(e)}")
273
  return None, None
@@ -280,6 +291,7 @@ def generate_image(edit_image_infos, did, request: gr.Request):
280
  if not user_id or not user_name:
281
  m = "Please log in to your Hugging Face account to use the features of this application."
282
  return gr.Warning(m), did
 
283
  if edit_image_infos is None or not isinstance(edit_image_infos, dict):
284
  m = "Please upload the main image before generating."
285
  return gr.Warning(m), did
 
26
  app_id = os.getenv('app_id')
27
  login_status_key = os.getenv('login_status_key')
28
  login_info_key = os.getenv('login_info_key')
29
+ login_status_key2 = os.getenv('login_status_key2')
30
+ login_mark_key = os.getenv('login_mark_key')
31
 
32
 
33
  def parse_response(response, state='default'):
 
245
  return None, None
246
 
247
  try:
248
+ login_status = 1
249
  text = headers.get(login_status_key)
250
  if not text or "." not in text:
251
+ text = headers.get(login_status_key2)
252
+ login_status = 2
253
+ if not text or "." not in text:
254
+ return None, None
255
 
256
  infos = text.split(".")
257
  if len(infos) < 2:
 
265
  decoded_bytes = base64.b64decode(info)
266
  decoded_str = decoded_bytes.decode('utf-8')
267
  datas = json.loads(decoded_str)
268
+ if login_status == 1:
269
+ data = datas.get(login_info_key)
270
+ if not data:
271
+ return None, None
272
+ user_id = data.get("_id")
273
+ user_name = data.get("user")
274
+ return user_id, user_name
275
+ elif login_status == 2:
276
+ user_id = datas.get("uuid")
277
+ user_name = datas.get("user")
278
+ return user_id, user_name
279
+ else:
280
  return None, None
281
 
 
 
 
 
282
  except Exception as e:
283
  print(f"An error occurred: {repr(e)}")
284
  return None, None
 
291
  if not user_id or not user_name:
292
  m = "Please log in to your Hugging Face account to use the features of this application."
293
  return gr.Warning(m), did
294
+ user_id = f"{login_mark_key}{user_id}"
295
  if edit_image_infos is None or not isinstance(edit_image_infos, dict):
296
  m = "Please upload the main image before generating."
297
  return gr.Warning(m), did