Spaces:
Build error
Build error
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,41 @@
|
|
| 1 |
-
from
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import HfApi, HfFolder
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
# --- Configuration ---
|
| 5 |
+
# Your Hugging Face username
|
| 6 |
+
hf_username = "your-hf-username"
|
| 7 |
+
# The name of the new repository
|
| 8 |
+
repo_name = "deepseek-chatbot"
|
| 9 |
+
# The local path to your app.py file
|
| 10 |
+
local_app_py_path = "app.py"
|
| 11 |
+
# The path where the file should be in the repository
|
| 12 |
+
repo_app_py_path = "app.py"
|
| 13 |
+
# Your Hugging Face API token (replace with your actual token)
|
| 14 |
+
hf_token = "your-hf-token"
|
| 15 |
+
|
| 16 |
+
# --- Script ---
|
| 17 |
+
api = HfApi()
|
| 18 |
+
repo_id = f"{hf_username}/{repo_name}"
|
| 19 |
+
|
| 20 |
+
# Create the repository if it doesn't exist
|
| 21 |
+
try:
|
| 22 |
+
api.create_repo(repo_id=repo_id, token=hf_token, repo_type="space", space_sdk="docker")
|
| 23 |
+
print(f"Repository '{repo_id}' created on Hugging Face Hub.")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"Repository '{repo_id}' may already exist: {e}")
|
| 26 |
+
|
| 27 |
+
# Read the content of the app.py file
|
| 28 |
+
app_py_content = Path(local_app_py_path).read_text()
|
| 29 |
+
|
| 30 |
+
# Commit the app.py file to the repository
|
| 31 |
+
try:
|
| 32 |
+
api.upload_file(
|
| 33 |
+
path_or_fileobj=app_py_content.encode("utf-8"),
|
| 34 |
+
path_in_repo=repo_app_py_path,
|
| 35 |
+
repo_id=repo_id,
|
| 36 |
+
token=hf_token,
|
| 37 |
+
commit_message="Add app.py for DeepSeek chatbot",
|
| 38 |
+
)
|
| 39 |
+
print(f"File '{repo_app_py_path}' committed to repository '{repo_id}'.")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Error committing file: {e}")
|