Spaces:
Build error
Build error
| 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}") |