broadfield-dev commited on
Commit
a7cd005
·
verified ·
1 Parent(s): bd380de

Update tools/space_builder.py

Browse files
Files changed (1) hide show
  1. tools/space_builder.py +5 -5
tools/space_builder.py CHANGED
@@ -59,11 +59,11 @@ def update_huggingface_space_file(owner: str, space_name: str, file_path: str, n
59
  return {"result": result}
60
  except Exception as e:
61
  if "is not in the list of choices" in str(e):
62
- return {"error": f"The file '{file_path}' could not be selected for update. It may not exist in the space."}
63
  logger.error(f"SPACE_BUILDER: An error occurred during file update: {e}", exc_info=True)
64
  return {"error": f"An API or client error occurred: {e}"}
65
 
66
- def list_space_files(owner: str, space_name: str):
67
  if not _initialize_client():
68
  return {"error": "Space builder client could not be initialized."}
69
  hf_token = os.getenv("HF_TOKEN")
@@ -71,18 +71,18 @@ def list_space_files(owner: str, space_name: str):
71
  return {"error": "Hugging Face token (HF_TOKEN) is not set in environment variables."}
72
  logger.info(f"SPACE_BUILDER: Calling /handle_load_space_files_list for {owner}/{space_name}")
73
  try:
74
- status_msg, file_list, _ = client.predict(
75
  token_from_ui=hf_token,
76
  space_name=space_name,
77
  owner_name=owner,
78
  api_name="/handle_load_space_files_list"
79
  )
80
- return {"status": status_msg, "files": file_list}
81
  except Exception as e:
82
  logger.error(f"SPACE_BUILDER: An error occurred while listing files: {e}", exc_info=True)
83
  return {"error": f"An API or client error occurred: {e}"}
84
 
85
- def get_space_file_content(owner: str, space_name: str, file_path: str):
86
  if not _initialize_client():
87
  return {"error": "Space builder client could not be initialized."}
88
  hf_token = os.getenv("HF_TOKEN")
 
59
  return {"result": result}
60
  except Exception as e:
61
  if "is not in the list of choices" in str(e):
62
+ return {"error": f"The file '{file_path}' could not be selected for update. It may not exist."}
63
  logger.error(f"SPACE_BUILDER: An error occurred during file update: {e}", exc_info=True)
64
  return {"error": f"An API or client error occurred: {e}"}
65
 
66
+ def list_huggingface_space_files(owner: str, space_name: str):
67
  if not _initialize_client():
68
  return {"error": "Space builder client could not be initialized."}
69
  hf_token = os.getenv("HF_TOKEN")
 
71
  return {"error": "Hugging Face token (HF_TOKEN) is not set in environment variables."}
72
  logger.info(f"SPACE_BUILDER: Calling /handle_load_space_files_list for {owner}/{space_name}")
73
  try:
74
+ status_msg, files_list, _ = client.predict(
75
  token_from_ui=hf_token,
76
  space_name=space_name,
77
  owner_name=owner,
78
  api_name="/handle_load_space_files_list"
79
  )
80
+ return {"status": status_msg, "files": files_list}
81
  except Exception as e:
82
  logger.error(f"SPACE_BUILDER: An error occurred while listing files: {e}", exc_info=True)
83
  return {"error": f"An API or client error occurred: {e}"}
84
 
85
+ def get_huggingface_space_file_content(owner: str, space_name: str, file_path: str):
86
  if not _initialize_client():
87
  return {"error": "Space builder client could not be initialized."}
88
  hf_token = os.getenv("HF_TOKEN")