CISCai commited on
Commit
c028c60
·
verified ·
1 Parent(s): 37e11f9

Cleaner gated/private failure using the new auth_check()

Browse files
Files changed (2) hide show
  1. app.py +90 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,7 +4,7 @@ import posixpath
4
  from fastapi import HTTPException, Path, Query, Request
5
  from fastapi.responses import StreamingResponse
6
  from gradio_huggingfacehub_search import HuggingfaceHubSearch
7
- from huggingface_hub import HfApi, HfFileSystem
8
  from typing import Annotated, Any, NamedTuple
9
  from urllib.parse import urlencode
10
 
@@ -576,7 +576,7 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
576
  )
577
  branches = [b.name for b in refs.branches]
578
  except Exception as e:
579
- raise gr.Error(e)
580
 
581
  return {
582
  hf_branch: gr.Dropdown(
@@ -597,6 +597,15 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
597
  ],
598
  outputs = [
599
  hf_file,
 
 
 
 
 
 
 
 
 
600
  ] + file_change_components,
601
  )
602
  def get_files(
@@ -604,13 +613,64 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
604
  branch: str | None,
605
  oauth_token: gr.OAuthToken | None = None,
606
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
  return {
608
  hf_file: FileExplorer(
609
  "**/*.gguf",
610
  file_count = "single",
611
  root_dir = repo,
612
  branch = branch,
613
- token = oauth_token.token if oauth_token else None,
614
  visible = True,
615
  ),
616
  meta_changes: gr.HighlightedText(
@@ -628,6 +688,33 @@ Any framework based on `llama-cpp-python` will let you select which chat templat
628
  btn_download: gr.Button(
629
  visible = False,
630
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  }
632
 
633
 
 
4
  from fastapi import HTTPException, Path, Query, Request
5
  from fastapi.responses import StreamingResponse
6
  from gradio_huggingfacehub_search import HuggingfaceHubSearch
7
+ from huggingface_hub import HfApi, HfFileSystem, auth_check
8
  from typing import Annotated, Any, NamedTuple
9
  from urllib.parse import urlencode
10
 
 
576
  )
577
  branches = [b.name for b in refs.branches]
578
  except Exception as e:
579
+ pass
580
 
581
  return {
582
  hf_branch: gr.Dropdown(
 
597
  ],
598
  outputs = [
599
  hf_file,
600
+ meta_types,
601
+ btn_delete,
602
+ meta_boolean,
603
+ meta_token_select,
604
+ meta_token_type,
605
+ meta_lookup,
606
+ meta_number,
607
+ meta_string,
608
+ meta_array,
609
  ] + file_change_components,
610
  )
611
  def get_files(
 
613
  branch: str | None,
614
  oauth_token: gr.OAuthToken | None = None,
615
  ):
616
+ try:
617
+ auth_check(repo, token=oauth_token.token if oauth_token else False)
618
+ except Exception as e:
619
+ gr.Warning(str(e))
620
+
621
+ return {
622
+ hf_file: FileExplorer(
623
+ root_dir = None,
624
+ visible = False,
625
+ ),
626
+ meta_changes: gr.HighlightedText(
627
+ visible = False,
628
+ ),
629
+ file_meta: gr.Matrix(
630
+ visible = False,
631
+ ),
632
+ meta_keys: gr.Dropdown(
633
+ visible = False,
634
+ ),
635
+ btn_download: gr.Button(
636
+ visible = False,
637
+ ),
638
+ meta_types: gr.Dropdown(
639
+ visible = False,
640
+ ),
641
+ btn_delete: gr.Button(
642
+ visible = False,
643
+ ),
644
+ meta_boolean: gr.Checkbox(
645
+ visible = False,
646
+ ),
647
+ meta_token_select: gr.Dropdown(
648
+ visible = False,
649
+ ),
650
+ meta_token_type: gr.Dropdown(
651
+ visible = False,
652
+ ),
653
+ meta_lookup: gr.Dropdown(
654
+ visible = False,
655
+ ),
656
+ meta_number: gr.Number(
657
+ visible = False,
658
+ ),
659
+ meta_string: gr.Textbox(
660
+ visible = False,
661
+ ),
662
+ meta_array: gr.Matrix(
663
+ visible = False,
664
+ ),
665
+ }
666
+
667
  return {
668
  hf_file: FileExplorer(
669
  "**/*.gguf",
670
  file_count = "single",
671
  root_dir = repo,
672
  branch = branch,
673
+ token = oauth_token.token if oauth_token else False,
674
  visible = True,
675
  ),
676
  meta_changes: gr.HighlightedText(
 
688
  btn_download: gr.Button(
689
  visible = False,
690
  ),
691
+ meta_types: gr.Dropdown(
692
+ visible = False,
693
+ ),
694
+ btn_delete: gr.Button(
695
+ visible = False,
696
+ ),
697
+ meta_boolean: gr.Checkbox(
698
+ visible = False,
699
+ ),
700
+ meta_token_select: gr.Dropdown(
701
+ visible = False,
702
+ ),
703
+ meta_token_type: gr.Dropdown(
704
+ visible = False,
705
+ ),
706
+ meta_lookup: gr.Dropdown(
707
+ visible = False,
708
+ ),
709
+ meta_number: gr.Number(
710
+ visible = False,
711
+ ),
712
+ meta_string: gr.Textbox(
713
+ visible = False,
714
+ ),
715
+ meta_array: gr.Matrix(
716
+ visible = False,
717
+ ),
718
  }
719
 
720
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  # gradio[oauth]==4.42.0
 
2
  gradio_huggingfacehub_search==0.0.7
 
1
  # gradio[oauth]==4.42.0
2
+ huggingface_hub==0.25.0
3
  gradio_huggingfacehub_search==0.0.7