Spaces:
Running
Running
File size: 1,298 Bytes
9975fc0 b2932a8 9975fc0 b2932a8 76d8efa 9975fc0 b2932a8 9975fc0 b2932a8 9975fc0 b2932a8 a5c1f8f 9975fc0 b2932a8 9975fc0 |
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
import time
from huggingface_hub import HfApi
import crediantials
# Set up Hugging Face credentials
HF_TOKEN = crediantials.HF_TOKEN
REPO_ID = crediantials.REPO_ID # Replace with your repo
# Set the full file path
def create_temp_file(local_file_path):
"""Creates a temporary file at the given path with unique content."""
os.makedirs(os.path.dirname(local_file_path), exist_ok=True) # Ensure the folder exists
with open(local_file_path, "w") as temp_file:
temp_file.write(f"Temporary file content - {time.time()}") # Add timestamp
def upload_file(local_file_path):
"""Uploads the local file to Hugging Face Hub."""
api = HfApi()
api.upload_file(
path_or_fileobj=local_file_path,
path_in_repo=os.path.basename(local_file_path), # Keep the same name on HF
repo_id=REPO_ID,
repo_type="space",
token=HF_TOKEN,
)
print(f"File {local_file_path} uploaded successfully! to hugging face ")
def main():
local_file_path = "/path/to/your/folder/uploaded_file.txt"
create_temp_file(local_file_path) # Create file at specified path
upload_file(local_file_path) # Upload to Hugging Face
os.remove(local_file_path) # Clean up local file after upload
if __name__ == "__main__":
main()
|