WeShop commited on
Commit
6302421
·
1 Parent(s): bebf8a9
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -26,6 +26,8 @@ agent_name = os.getenv('agent_name')
26
 
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):
@@ -222,9 +224,13 @@ def check_login_status(headers):
222
  return None, None
223
 
224
  try:
 
225
  text = headers.get(login_status_key)
226
  if not text or "." not in text:
227
- return None, None
 
 
 
228
 
229
  infos = text.split(".")
230
  if len(infos) < 2:
@@ -238,15 +244,20 @@ def check_login_status(headers):
238
  decoded_bytes = base64.b64decode(info)
239
  decoded_str = decoded_bytes.decode('utf-8')
240
  datas = json.loads(decoded_str)
241
-
242
- data = datas.get(login_info_key)
243
- if not data:
 
 
 
 
 
 
 
 
 
244
  return None, None
245
 
246
- user_id = data.get("_id")
247
- user_name = data.get("user")
248
- return user_id, user_name
249
-
250
  except Exception as e:
251
  print(f"An error occurred: {repr(e)}")
252
  return None, None
@@ -259,6 +270,7 @@ def generate_image(main_image, text_description, did, request: gr.Request):
259
  if not user_id or not user_name:
260
  m = "Please log in to your Hugging Face account to use the features of this application."
261
  return gr.Warning(m), did
 
262
  if main_image is None:
263
  m = "Please upload both the main image and the background reference image before generating."
264
  return gr.Warning(m), did
 
26
 
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):
 
224
  return None, None
225
 
226
  try:
227
+ login_status = 1
228
  text = headers.get(login_status_key)
229
  if not text or "." not in text:
230
+ text = headers.get(login_status_key2)
231
+ login_status = 2
232
+ if not text or "." not in text:
233
+ return None, None
234
 
235
  infos = text.split(".")
236
  if len(infos) < 2:
 
244
  decoded_bytes = base64.b64decode(info)
245
  decoded_str = decoded_bytes.decode('utf-8')
246
  datas = json.loads(decoded_str)
247
+ if login_status == 1:
248
+ data = datas.get(login_info_key)
249
+ if not data:
250
+ return None, None
251
+ user_id = data.get("_id")
252
+ user_name = data.get("user")
253
+ return user_id, user_name
254
+ elif login_status == 2:
255
+ user_id = datas.get("uuid")
256
+ user_name = datas.get("user")
257
+ return user_id, user_name
258
+ else:
259
  return None, None
260
 
 
 
 
 
261
  except Exception as e:
262
  print(f"An error occurred: {repr(e)}")
263
  return None, None
 
270
  if not user_id or not user_name:
271
  m = "Please log in to your Hugging Face account to use the features of this application."
272
  return gr.Warning(m), did
273
+ user_id = f"{login_mark_key}{user_id}"
274
  if main_image is None:
275
  m = "Please upload both the main image and the background reference image before generating."
276
  return gr.Warning(m), did