Spaces:
Build error
Build error
File size: 1,330 Bytes
317d95a | 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 | from huggingface_hub import HfApi, HfFolder
from pathlib import Path
# --- Configuration ---
# Your Hugging Face username
hf_username = "your-hf-username"
# The name of the new repository
repo_name = "deepseek-chatbot"
# The local path to your app.py file
local_app_py_path = "app.py"
# The path where the file should be in the repository
repo_app_py_path = "app.py"
# Your Hugging Face API token (replace with your actual token)
hf_token = "your-hf-token"
# --- Script ---
api = HfApi()
repo_id = f"{hf_username}/{repo_name}"
# Create the repository if it doesn't exist
try:
api.create_repo(repo_id=repo_id, token=hf_token, repo_type="space", space_sdk="docker")
print(f"Repository '{repo_id}' created on Hugging Face Hub.")
except Exception as e:
print(f"Repository '{repo_id}' may already exist: {e}")
# Read the content of the app.py file
app_py_content = Path(local_app_py_path).read_text()
# Commit the app.py file to the repository
try:
api.upload_file(
path_or_fileobj=app_py_content.encode("utf-8"),
path_in_repo=repo_app_py_path,
repo_id=repo_id,
token=hf_token,
commit_message="Add app.py for DeepSeek chatbot",
)
print(f"File '{repo_app_py_path}' committed to repository '{repo_id}'.")
except Exception as e:
print(f"Error committing file: {e}") |