Spaces:
Runtime error
Runtime error
File size: 1,556 Bytes
3a2b1aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from huggingface_hub import HfApi, create_repo
import os
def deploy():
api = HfApi()
username = api.whoami()["name"]
repo_name = "CNN-CIFAR10-Classifier"
repo_id = f"{username}/{repo_name}"
print(f"Deploying to Space: {repo_id}")
# Clean up existing repo to free quota
try:
from huggingface_hub import delete_repo
print("Deleting existing repository to ensure clean state...")
delete_repo(repo_id, repo_type="space")
print("Repository deleted.")
except Exception as e:
print(f"Repository deletion skipped or failed (might not exist): {e}")
# Create the Space
try:
create_repo(repo_id, repo_type="space", space_sdk="docker", private=False)
print("Space repository created.")
except Exception as e:
print(f"Creation error: {e}")
# Determine ignore patterns
ignore_patterns = [
".git*",
".venv*",
"__pycache__*",
"*.pyc",
".DS_Store",
"data/*", # Exclude dataset
"MNIST/*", # Exclude unrelated folder
"uploads/*" # Exclude user uploads
]
print("Uploading files...")
api.upload_folder(
folder_path=".",
repo_id=repo_id,
repo_type="space",
ignore_patterns=ignore_patterns,
commit_message="Deploying CNN App (clean)"
)
print(f"Successfully uploaded files to https://huggingface.co/spaces/{repo_id}")
if __name__ == "__main__":
deploy()
|