broadfield-dev commited on
Commit
30672bd
·
verified ·
1 Parent(s): 199d4ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -7,7 +7,6 @@ import string
7
  import logging
8
  import black
9
 
10
- user_="broadfield-dev"
11
  # Configure logging
12
  logging.basicConfig(level=logging.INFO)
13
  logger = logging.getLogger(__name__)
@@ -18,17 +17,16 @@ from assembler_docs import DOCUMENTATION
18
  app = Flask(__name__)
19
 
20
  # Hugging Face API token (set in Space settings)
21
- #HF_TOKEN = os.getenv("HF_TOKEN")
22
- HF_TOKEN = ""
23
- #if not HF_TOKEN:
24
- # raise ValueError("HF_TOKEN not set. Add it in Space settings.")
25
 
26
  # Log in to Hugging Face Hub with the token
27
- #try:
28
- #login(token="")
29
- #logger.info("Successfully logged in to Hugging Face Hub")
30
- #except Exception as e:
31
- # raise ValueError(f"Failed to log in to Hugging Face Hub: {str(e)}")
32
 
33
  hf_api = HfApi()
34
 
@@ -47,7 +45,7 @@ def verify_organization_access(organization: str, token: str) -> bool:
47
  except Exception as e:
48
  logger.error(f"No write access to organization {organization}: {str(e)}")
49
  return False
50
- '''def build_space(repo_name,file_name,file_content,access_token=""):
51
  try:
52
  repo_path=user_+str(repo_)
53
  access_token=os.environ['HF_TOKEN']
@@ -77,7 +75,7 @@ def verify_organization_access(organization: str, token: str) -> bool:
77
  return [{'role':'assistant','content': commit_message+'\nCommit Success' }]
78
  except Exception as e:
79
  print("ERROR ",e)
80
- return [{'role':'assistant','content': 'There was an Error: ' + str(e)}]'''
81
 
82
  @app.route('/create-space', methods=['POST'])
83
  def create_hf_space():
@@ -101,7 +99,7 @@ def create_hf_space():
101
  return jsonify({"error": f"Invalid space_type. Must be one of {valid_space_types}"}), 400
102
 
103
  # Organization namespace for new Spaces
104
- ORGANIZATION = user_
105
  space_name = generate_space_name()
106
  full_repo_id = f"{ORGANIZATION}/{space_name}"
107
 
@@ -124,7 +122,7 @@ def create_hf_space():
124
 
125
  # Verify repository existence before uploading
126
  try:
127
- repo_exists = api.repo_exists(repo_id=full_repo_id, repo_type="space")
128
  if not repo_exists:
129
  return jsonify({"error": f"Repository {full_repo_id} does not exist after creation attempt."}), 500
130
  logger.info(f"Verified repository exists: {full_repo_id}")
 
7
  import logging
8
  import black
9
 
 
10
  # Configure logging
11
  logging.basicConfig(level=logging.INFO)
12
  logger = logging.getLogger(__name__)
 
17
  app = Flask(__name__)
18
 
19
  # Hugging Face API token (set in Space settings)
20
+ HF_TOKEN = os.getenv("HF_TOKEN")
21
+ if not HF_TOKEN:
22
+ raise ValueError("HF_TOKEN not set. Add it in Space settings.")
 
23
 
24
  # Log in to Hugging Face Hub with the token
25
+ try:
26
+ login(token=HF_TOKEN)
27
+ logger.info("Successfully logged in to Hugging Face Hub")
28
+ except Exception as e:
29
+ raise ValueError(f"Failed to log in to Hugging Face Hub: {str(e)}")
30
 
31
  hf_api = HfApi()
32
 
 
45
  except Exception as e:
46
  logger.error(f"No write access to organization {organization}: {str(e)}")
47
  return False
48
+ def build_space(repo_name,file_name,file_content,access_token=""):
49
  try:
50
  repo_path=user_+str(repo_)
51
  access_token=os.environ['HF_TOKEN']
 
75
  return [{'role':'assistant','content': commit_message+'\nCommit Success' }]
76
  except Exception as e:
77
  print("ERROR ",e)
78
+ return [{'role':'assistant','content': 'There was an Error: ' + str(e)}]
79
 
80
  @app.route('/create-space', methods=['POST'])
81
  def create_hf_space():
 
99
  return jsonify({"error": f"Invalid space_type. Must be one of {valid_space_types}"}), 400
100
 
101
  # Organization namespace for new Spaces
102
+ ORGANIZATION = "Space-Share"
103
  space_name = generate_space_name()
104
  full_repo_id = f"{ORGANIZATION}/{space_name}"
105
 
 
122
 
123
  # Verify repository existence before uploading
124
  try:
125
+ repo_exists = hf_api.repo_exists(repo_id=full_repo_id, repo_type="space")
126
  if not repo_exists:
127
  return jsonify({"error": f"Repository {full_repo_id} does not exist after creation attempt."}), 500
128
  logger.info(f"Verified repository exists: {full_repo_id}")