Spaces:
Running
Running
| import os | |
| from huggingface_hub import HfApi | |
| # Configuration | |
| REPO_ID = "shadowsilence/burmese-english-translator" | |
| REPO_TYPE = "space" | |
| PROJECT_ROOT = "/Users/htutkoko/Library/CloudStorage/GoogleDrive-htutkoko1994@gmail.com/My Drive/NLP/Project_A3/A3_Burmese_English_Puffer" | |
| APP_PATH = os.path.join(PROJECT_ROOT, "app") | |
| api = HfApi() | |
| print(f"Starting FULL CLEANUP and RE-DEPLOYMENT to {REPO_ID}...") | |
| # 1. Nuclear Option: Delete ALL existing files on the Hub to start fresh | |
| try: | |
| print("Listing existing files on Hub...") | |
| all_files = api.list_repo_files(repo_id=REPO_ID, repo_type=REPO_TYPE) | |
| # Identify top-level items to delete to clean the repo | |
| # We delete paths that don't look like hidden git files | |
| paths_to_delete = [] | |
| for f in all_files: | |
| # Get the top-level part of the path | |
| parts = f.split('/') | |
| root_item = parts[0] | |
| if root_item not in ['.gitattributes', '.gitignore', 'README.md'] and root_item not in paths_to_delete: | |
| paths_to_delete.append(root_item) | |
| print(f"Deleting the following root items: {paths_to_delete}") | |
| for item in paths_to_delete: | |
| try: | |
| # Try deleting as a folder first (most common for 'app', 'models') | |
| print(f"Deleting folder: {item}...") | |
| api.delete_folder(repo_id=REPO_ID, repo_type=REPO_TYPE, folder_path=item) | |
| except: | |
| # Fallback to file delete | |
| try: | |
| print(f"Deleting file: {item}...") | |
| api.delete_file(repo_id=REPO_ID, repo_type=REPO_TYPE, path_in_repo=item) | |
| except Exception as e: | |
| print(f"Could not delete {item}: {e}") | |
| print("Cleanup complete. Starting fresh upload...") | |
| # 2. Upload Dockerfile and requirements.txt to root | |
| files_to_upload = ["Dockerfile", "requirements.txt"] | |
| for file in files_to_upload: | |
| local_path = os.path.join(PROJECT_ROOT, file) | |
| if os.path.exists(local_path): | |
| print(f"Uploading {file}...") | |
| api.upload_file( | |
| path_or_fileobj=local_path, | |
| path_in_repo=file, | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE | |
| ) | |
| # 3. Upload the entire 'app' directory (code + models + static) | |
| print("Uploading 'app' directory (this may take a moment)...") | |
| api.upload_folder( | |
| folder_path=APP_PATH, | |
| path_in_repo="app", | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE, | |
| commit_message="Full clean redeploy with verified models", | |
| # Explicitly allow everything we need | |
| allow_patterns=["**"] | |
| ) | |
| print("SUCCESS: Full redeployment finished!") | |
| except Exception as e: | |
| print(f"Deployment failed: {e}") | |