File size: 2,737 Bytes
fba0a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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}")