File size: 1,457 Bytes
90c9c63
ed7b69c
90c9c63
ed7b69c
90c9c63
ed7b69c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90c9c63
 
 
 
 
 
 
 
 
 
 
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
import os
from pathlib import Path

from huggingface_hub import login, upload_folder, whoami

# Check if already logged in
try:
    user_info = whoami()
    print(f"Already logged in as: {user_info.get('name', 'Unknown')}")
except Exception:
    # Not logged in, need to authenticate
    print("Not logged in. Checking for saved token...")

    # Try to get token from environment variable first
    hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")

    # If not in environment, try to read from Hugging Face cache
    if not hf_token:
        cache_token_path = Path.home() / ".cache" / "huggingface" / "token"
        if cache_token_path.exists():
            try:
                hf_token = cache_token_path.read_text().strip()
                if hf_token:
                    print("Found token in cache.")
            except Exception:
                pass

    # Login with token (will prompt if token is None and not found)
    # add_to_git_credential=True saves it to git credential helper for future use
    login(token=hf_token, add_to_git_credential=True)

# Get current directory (absolute path of this script)
current_dir = os.path.abspath(os.path.dirname(__file__))
print(f"Current directory: {current_dir}")

# Upload the current folder (contents of the directory this script is in)
upload_folder(
    folder_path=current_dir,
    repo_id="NiklasAbraham/MoviePlotEmbeddingsDataset",
    repo_type="dataset",
)