Team Ai
Apppublic

alphanet06/processor2

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
force_commit_credentials.py113 linesDownload Raw Back to root
1#!/usr/bin/env python3
2"""
3Force commit Google Drive credentials and push to HuggingFace
4"""
5
6import subprocess
7import os
8from pathlib import Path
9
10def run_command(command, description=""):
11    """Run a command and show output"""
12    print(f"๐Ÿ”„ {description}")
13    print(f"   Command: {command}")
14
15    try:
16        result = subprocess.run(command, shell=True, capture_output=True, text=True)
17        if result.stdout:
18            print(f"   โœ… Output: {result.stdout.strip()}")
19        if result.stderr:
20            print(f"   โš ๏ธ  Warning: {result.stderr.strip()}")
21        return result.returncode == 0
22    except Exception as e:
23        print(f"   โŒ Error: {e}")
24        return False
25
26def force_commit_credentials():
27    """Force commit the Google Drive credentials"""
28    print("=" * 60)
29    print("๐Ÿš€ Force Commit Google Drive Credentials")
30    print("=" * 60)
31    print()
32
33    # Check if files exist locally
34    required_files = ['credentials.json', 'settings.yaml', 'client_secrets.json']
35
36    print("๐Ÿ“‹ Checking required files:")
37    for filename in required_files:
38        if Path(filename).exists():
39            size = Path(filename).stat().st_size
40            print(f"   โœ… {filename} ({size} bytes)")
41        else:
42            print(f"   โŒ {filename} (missing!)")
43            return False
44
45    print()
46
47    # Check git status
48    success = run_command("git status --porcelain", "Checking git status...")
49    if not success:
50        return False
51
52    # Add files (force for credentials.json since it was in .gitignore)
53    files_to_add = required_files + ['app.py', 'requirements.txt']
54    for filename in files_to_add:
55        if Path(filename).exists():
56            success = run_command(f"git add -f {filename}", f"Adding {filename}...")
57            if not success:
58                return False
59
60    print()
61
62    # Check if there are changes to commit
63    success, output, error = run_command("git status --porcelain", "Checking for changes to commit...")
64    if not output.strip():
65        print("โ„น๏ธ  No changes to commit")
66        return True
67
68    print()
69
70    # Commit the changes
71    success = run_command(
72        'git commit -m "Add Google Drive authentication files and integration"',
73        "Committing changes..."
74    )
75    if not success:
76        return False
77
78    print()
79
80    # Push to remote
81    success = run_command("git push", "Pushing to remote...")
82    if not success:
83        return False
84
85    print()
86    print("=" * 60)
87    print("โœ… SUCCESS! Files committed and pushed!")
88    print("=" * 60)
89    print()
90    print("๐Ÿ“ค Next steps:")
91    print("   1. Wait 1-2 minutes for HuggingFace to process")
92    print("   2. Force rebuild the space if needed:")
93    print("      - Go to space settings")
94    print("      - Click 'Rebuild space' or 'Restart space'")
95    print()
96    print("   3. Check if it works:")
97    print("      Visit: https://your-space.hf.space/debug")
98    print("      Should show credentials.json in file listing")
99    print()
100    print("   4. Final test:")
101    print("      Visit: https://your-space.hf.space/check_gdrive")
102
103    return True
104
105if __name__ == "__main__":
106    success = force_commit_credentials()
107    if not success:
108        print()
109        print("โŒ Failed to commit credentials")
110        print("   Check the errors above and try again")
111        exit(1)
112
113