WeShop commited on
Commit
f7c696e
·
1 Parent(s): 784a144
Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +20 -52
README.md CHANGED
@@ -9,6 +9,7 @@ app_file: app.py
9
  pinned: false
10
  license: other
11
  short_description: WeShopAI Bad Hand Fixer. Fix hand areas in photos easily.
 
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  pinned: false
10
  license: other
11
  short_description: WeShopAI Bad Hand Fixer. Fix hand areas in photos easily.
12
+ hf_oauth: true
13
  ---
14
 
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -9,6 +9,7 @@ from PIL import Image
9
  import uuid
10
  import base64
11
  import json
 
12
 
13
  example_path = os.path.join(os.path.dirname(__file__), 'assets')
14
  clothing_list = os.listdir(os.path.join(example_path, "clothing"))
@@ -240,62 +241,27 @@ def image_to_base64(image):
240
  return f"data:image/png;base64,{img_base64}"
241
 
242
 
243
- def check_login_status(headers):
244
- if not headers:
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:
258
- return None, None
259
-
260
- info = infos[1]
261
- cover = len(info) % 4
262
- if cover != 0:
263
- info += "=" * (4 - cover)
264
-
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
285
-
286
-
287
- def generate_image(edit_image_infos, did, request: gr.Request):
288
  if not did:
289
  did = str(uuid.uuid4())
290
- user_id, user_name = check_login_status(request.request.headers)
291
- if not user_id:
292
- user_id = request.session_hash
293
- if not user_name:
294
- user_name = request.session_hash
 
 
 
 
 
 
 
 
 
 
295
  if not user_id or not user_name:
296
- m = "Please log in to your Hugging Face account to use the features of this application."
297
  return gr.Warning(m), did
298
- user_id = f"{login_hash_key}{user_id}"
299
  if edit_image_infos is None or not isinstance(edit_image_infos, dict):
300
  m = "Please upload the main image before generating."
301
  return gr.Warning(m), did
@@ -544,6 +510,8 @@ with gr.Blocks(css=css) as WeShop:
544
  outputs=[output, current_did],
545
  concurrency_limit=None
546
  )
 
 
547
  with gr.Column():
548
  main_image_middleware = gr.Image(
549
  image_mode='RGBA',
 
9
  import uuid
10
  import base64
11
  import json
12
+ from huggingface_hub import whoami
13
 
14
  example_path = os.path.join(os.path.dirname(__file__), 'assets')
15
  clothing_list = os.listdir(os.path.join(example_path, "clothing"))
 
241
  return f"data:image/png;base64,{img_base64}"
242
 
243
 
244
+ def generate_image(edit_image_infos, did, request: gr.Request, oauth_token: gr.OAuthToken | None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  if not did:
246
  did = str(uuid.uuid4())
247
+ if not oauth_token:
248
+ m = "Please click the authorization button below the Generate button to authorize."
249
+ return gr.Warning(m), did
250
+ user_id = None
251
+ user_name = None
252
+ try:
253
+ oauth_infos = whoami(oauth_token.token)
254
+ print(f"oauth_infos={oauth_infos}")
255
+ if oauth_infos and isinstance(oauth_infos, dict):
256
+ user_id = oauth_infos.get('id')
257
+ user_name = oauth_infos.get('name')
258
+ except Exception as e:
259
+ print(f"error: {repr(e)}")
260
+ m = "There was an error processing the authorization information. Please refresh the page and try again."
261
+ return gr.Warning(m), did
262
  if not user_id or not user_name:
263
+ m = "Missing user login information. Please check and try refreshing the page."
264
  return gr.Warning(m), did
 
265
  if edit_image_infos is None or not isinstance(edit_image_infos, dict):
266
  m = "Please upload the main image before generating."
267
  return gr.Warning(m), did
 
510
  outputs=[output, current_did],
511
  concurrency_limit=None
512
  )
513
+ with gr.Row():
514
+ gr.LoginButton()
515
  with gr.Column():
516
  main_image_middleware = gr.Image(
517
  image_mode='RGBA',