Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,37 +45,6 @@ def verify_organization_access(organization: str, token: str) -> bool:
|
|
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']
|
52 |
-
if not access_token:
|
53 |
-
return [{'role':'assistant','content': 'ENTER A HUGGINGFACE TOKEN'}]
|
54 |
-
api=HfApi(endpoint="https://huggingface.co", token=access_token)
|
55 |
-
repo_url = api.create_repo(
|
56 |
-
repo_id=repo_path,
|
57 |
-
repo_type="space",
|
58 |
-
space_sdk="gradio",
|
59 |
-
exist_ok=True,
|
60 |
-
private=False,
|
61 |
-
)
|
62 |
-
|
63 |
-
local_file_path=str(uuid.uuid4())
|
64 |
-
with open(file_name, 'w') as f:
|
65 |
-
f.write(str(file_content).strip("''").strip('""').strip("{}").format())
|
66 |
-
f.close()
|
67 |
-
# Upload a local file to the Space
|
68 |
-
commit_message = "Adding file test: "+ str(file_name)
|
69 |
-
|
70 |
-
api.upload_file(path_or_fileobj=file_name, path_in_repo=file_name.strip("./"), repo_id=repo_path, repo_type='space', commit_message=commit_message)
|
71 |
-
print("File uploaded successfully.")
|
72 |
-
# Commit changes
|
73 |
-
commit_message += "\nInitial commit to the repository."+ f'{repo_path}/' + f'{file_name}'
|
74 |
-
#api.commit_repo(space_id, message=commit_message)
|
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():
|
@@ -118,7 +87,8 @@ def create_hf_space():
|
|
118 |
)
|
119 |
logger.info(f"Repository created: {full_repo_id}")
|
120 |
except Exception as e:
|
121 |
-
return jsonify({"error": f"Failed to create repository {full_repo_id}: {str(e)}"}), 500
|
|
|
122 |
|
123 |
# Verify repository existence before uploading
|
124 |
try:
|
|
|
45 |
except Exception as e:
|
46 |
logger.error(f"No write access to organization {organization}: {str(e)}")
|
47 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
@app.route('/create-space', methods=['POST'])
|
50 |
def create_hf_space():
|
|
|
87 |
)
|
88 |
logger.info(f"Repository created: {full_repo_id}")
|
89 |
except Exception as e:
|
90 |
+
#return jsonify({"error": f"Failed to create repository {full_repo_id}: {str(e)}"}), 500
|
91 |
+
print f"Failed to create repository {full_repo_id}: {str(e)}"})
|
92 |
|
93 |
# Verify repository existence before uploading
|
94 |
try:
|