davidberenstein1957 HF staff commited on
Commit
46453e0
·
1 Parent(s): cad7678

docs: naming for code

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -39,10 +39,11 @@ def get_resource_type_dropdown(
39
  org_name: str, resource_type: str, oauth_token: OAuthToken = None
40
  ):
41
  if oauth_token is None:
42
- return []
 
 
43
 
44
  hf_client = HfApi(token=oauth_token.token)
45
-
46
  if resource_type == "model":
47
  resources = hf_client.list_models(author=org_name)
48
  elif resource_type == "dataset":
@@ -53,7 +54,6 @@ def get_resource_type_dropdown(
53
  resources = []
54
 
55
  resources = [resource.id for resource in resources]
56
-
57
  return gr.Dropdown(
58
  label="Resource",
59
  choices=resources,
@@ -63,8 +63,9 @@ def get_resource_type_dropdown(
63
 
64
  def get_resource(resource_id: str, resource_type: str, oauth_token: OAuthToken = None):
65
  if oauth_token is None:
66
- return []
67
-
 
68
  hf_client = HfApi(token=oauth_token.token)
69
 
70
  resource: ModelInfo | DatasetInfo | SpaceInfo = hf_client.repo_info(
@@ -78,7 +79,8 @@ def delete_resource(
78
  ):
79
  if oauth_token is None:
80
  return []
81
-
 
82
  hf_client = HfApi(token=oauth_token.token)
83
 
84
  hf_client.delete_repo(resource_id, repo_type=resource_type, missing_ok=True)
@@ -96,7 +98,7 @@ with gr.Blocks() as demo:
96
  value="dataset",
97
  )
98
  resources = gr.Dropdown(label="Resources")
99
- resource_info = gr.Code("Resource Info", language="json")
100
 
101
  org_name.change(
102
  get_resource_type_dropdown,
 
39
  org_name: str, resource_type: str, oauth_token: OAuthToken = None
40
  ):
41
  if oauth_token is None:
42
+ return ""
43
+ if not all([org_name, resource_type]):
44
+ return ""
45
 
46
  hf_client = HfApi(token=oauth_token.token)
 
47
  if resource_type == "model":
48
  resources = hf_client.list_models(author=org_name)
49
  elif resource_type == "dataset":
 
54
  resources = []
55
 
56
  resources = [resource.id for resource in resources]
 
57
  return gr.Dropdown(
58
  label="Resource",
59
  choices=resources,
 
63
 
64
  def get_resource(resource_id: str, resource_type: str, oauth_token: OAuthToken = None):
65
  if oauth_token is None:
66
+ return ""
67
+ if not all([resource_id, resource_type]):
68
+ return ""
69
  hf_client = HfApi(token=oauth_token.token)
70
 
71
  resource: ModelInfo | DatasetInfo | SpaceInfo = hf_client.repo_info(
 
79
  ):
80
  if oauth_token is None:
81
  return []
82
+ if not all([resource_id, resource_type]):
83
+ return []
84
  hf_client = HfApi(token=oauth_token.token)
85
 
86
  hf_client.delete_repo(resource_id, repo_type=resource_type, missing_ok=True)
 
98
  value="dataset",
99
  )
100
  resources = gr.Dropdown(label="Resources")
101
+ resource_info = gr.Code(language="json", label="Resource Info")
102
 
103
  org_name.change(
104
  get_resource_type_dropdown,