Update build_logic.py
Browse files- build_logic.py +37 -21
build_logic.py
CHANGED
@@ -23,25 +23,6 @@ logging.basicConfig(
|
|
23 |
)
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
26 |
-
def list_user_repos(username):
|
27 |
-
api = HfApi()
|
28 |
-
user_repos = {}
|
29 |
-
|
30 |
-
# List models for the user
|
31 |
-
models = api.list_models(author=username)
|
32 |
-
user_repos['models'] = [model.id for model in models]
|
33 |
-
|
34 |
-
# List datasets for the user
|
35 |
-
datasets = api.list_datasets(author=username)
|
36 |
-
user_repos['datasets'] = [dataset.id for dataset in datasets]
|
37 |
-
|
38 |
-
# List Spaces for the user
|
39 |
-
spaces = api.list_spaces(author=username)
|
40 |
-
user_repos['spaces'] = [space.id for space in spaces]
|
41 |
-
|
42 |
-
return user_repos
|
43 |
-
|
44 |
-
|
45 |
def _get_api_token(ui_token_from_textbox=None):
|
46 |
env_token = os.getenv('HF_TOKEN')
|
47 |
if env_token:
|
@@ -880,7 +861,23 @@ def list_user_spaces(hf_api_key, owner=None):
|
|
880 |
return None, f"Error auto-detecting owner for listing: {e}. Please specify Owner field."
|
881 |
|
882 |
api = HfApi(token=token)
|
883 |
-
spaces = hf_list_repos(effective_owner,token=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
884 |
space_ids = [f"{r.author}/{r.id}" for r in spaces]
|
885 |
|
886 |
logger.info(f"Successfully listed {len(space_ids)} spaces for {effective_owner}.")
|
@@ -896,4 +893,23 @@ def list_user_spaces(hf_api_key, owner=None):
|
|
896 |
return None, f"HTTP Error ({status_code}) listing spaces for '{owner or 'authenticated user'}': {e_http.response.text if e_http.response else str(e_http)}"
|
897 |
except Exception as e:
|
898 |
logger.exception(f"Error listing spaces for {owner or 'authenticated user'}:")
|
899 |
-
return None, f"Error listing spaces: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def _get_api_token(ui_token_from_textbox=None):
|
27 |
env_token = os.getenv('HF_TOKEN')
|
28 |
if env_token:
|
|
|
861 |
return None, f"Error auto-detecting owner for listing: {e}. Please specify Owner field."
|
862 |
|
863 |
api = HfApi(token=token)
|
864 |
+
#spaces = hf_list_repos(effective_owner,token=token)
|
865 |
+
|
866 |
+
user_repos = {}
|
867 |
+
|
868 |
+
# List models for the user
|
869 |
+
models = api.list_models(author=owner)
|
870 |
+
user_repos['models'] = [model.id for model in models]
|
871 |
+
|
872 |
+
# List datasets for the user
|
873 |
+
datasets = api.list_datasets(author=owner)
|
874 |
+
user_repos['datasets'] = [dataset.id for dataset in datasets]
|
875 |
+
|
876 |
+
# List Spaces for the user
|
877 |
+
spaces = api.list_spaces(author=owner)
|
878 |
+
user_repos['spaces'] = [space.id for space in spaces]
|
879 |
+
|
880 |
+
|
881 |
space_ids = [f"{r.author}/{r.id}" for r in spaces]
|
882 |
|
883 |
logger.info(f"Successfully listed {len(space_ids)} spaces for {effective_owner}.")
|
|
|
893 |
return None, f"HTTP Error ({status_code}) listing spaces for '{owner or 'authenticated user'}': {e_http.response.text if e_http.response else str(e_http)}"
|
894 |
except Exception as e:
|
895 |
logger.exception(f"Error listing spaces for {owner or 'authenticated user'}:")
|
896 |
+
return None, f"Error listing spaces: {e}"
|
897 |
+
|
898 |
+
|
899 |
+
def list_user_spaces(username):
|
900 |
+
api = HfApi()
|
901 |
+
user_repos = {}
|
902 |
+
|
903 |
+
# List models for the user
|
904 |
+
models = api.list_models(author=username)
|
905 |
+
user_repos['models'] = [model.id for model in models]
|
906 |
+
|
907 |
+
# List datasets for the user
|
908 |
+
datasets = api.list_datasets(author=username)
|
909 |
+
user_repos['datasets'] = [dataset.id for dataset in datasets]
|
910 |
+
|
911 |
+
# List Spaces for the user
|
912 |
+
spaces = api.list_spaces(author=username)
|
913 |
+
user_repos['spaces'] = [space.id for space in spaces]
|
914 |
+
|
915 |
+
return user_repos
|