File size: 672 Bytes
013cfce
d1479d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from dotenv import load_dotenv   
from huggingface_hub import HfApi

load_dotenv()
repo_id = "zaradana/temp_files"

api = HfApi()

def upload_file(file_local_path: str) -> str:
    """
    Upload a file to the Hugging Face Hub and return the URL
    Args:
        file_local_path: The local path to the file
    Returns:
        The URL of the uploaded file
    """
    file_name = file_local_path.split("/")[-1]

    api.upload_file(
        path_or_fileobj=file_local_path,
        path_in_repo=file_name,
        repo_id=repo_id,
        repo_type="dataset"
    )
    file_url = f"https://huggingface.co/datasets/{repo_id}/resolve/main/{file_name}"
    return file_url