multimodalart HF staff commited on
Commit
02a9af1
1 Parent(s): 054782c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -441,17 +441,21 @@ def run_captioning(*inputs):
441
  yield final_captions
442
 
443
  def check_token(token):
444
- api = HfApi(token=token)
445
- user_data = api.whoami()
446
- if (username['auth']['accessToken']['role'] != "write"):
447
- gr.Warning("Oops, you've uploaded a `Read` token. We need a Write token!")
448
  else:
449
- if user_data['canPay']:
450
- return gr.update(visible=False), gr.update(visible=True)
 
451
  else:
452
- return gr.update(visible=True), gr.update(visible=False)
453
-
454
- return gr.update(visible=False), gr.update(visible=False)
 
 
 
455
 
456
  with gr.Blocks() as demo:
457
  dataset_folder = gr.State()
 
441
  yield final_captions
442
 
443
  def check_token(token):
444
+ try:
445
+ api = HfApi(token=token)
446
+ except Exception as e:
447
+ gr.Warning("Invalid user token. Make sure to get your Hugging Face")
448
  else:
449
+ user_data = api.whoami()
450
+ if (username['auth']['accessToken']['role'] != "write"):
451
+ gr.Warning("Oops, you've uploaded a `Read` token. You need to use a Write token!")
452
  else:
453
+ if user_data['canPay']:
454
+ return gr.update(visible=False), gr.update(visible=True)
455
+ else:
456
+ return gr.update(visible=True), gr.update(visible=False)
457
+
458
+ return gr.update(visible=False), gr.update(visible=False)
459
 
460
  with gr.Blocks() as demo:
461
  dataset_folder = gr.State()