Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,36 @@ import os
|
|
| 2 |
import requests
|
| 3 |
from huggingface_hub import HfApi
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
dest_repo = "AIDev07/AIModelsLoaded"
|
| 8 |
filename = "starcoder2-15b-instruct-v0.1-Q4_K_M.gguf"
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
if not token:
|
| 13 |
-
print("β
|
| 14 |
else:
|
| 15 |
api = HfApi(token=token)
|
| 16 |
-
print(f"π Starting
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
# 2.
|
| 20 |
with requests.get(source_url, stream=True) as r:
|
| 21 |
r.raise_for_status()
|
| 22 |
|
| 23 |
-
# 3. Upload the
|
| 24 |
-
# This doesn't save to your phone; it stays on HF servers.
|
| 25 |
api.upload_file(
|
| 26 |
-
path_or_fileobj=r.raw,
|
| 27 |
path_in_repo=filename,
|
| 28 |
repo_id=dest_repo,
|
| 29 |
repo_type="dataset",
|
| 30 |
-
commit_message=f"
|
| 31 |
)
|
| 32 |
|
| 33 |
-
print(f"β
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
print(f"β Transfer Failed: {e}")
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
from huggingface_hub import HfApi
|
| 4 |
|
| 5 |
+
# 1. Configuration
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
dest_repo = "AIDev07/AIModelsLoaded"
|
| 8 |
filename = "starcoder2-15b-instruct-v0.1-Q4_K_M.gguf"
|
| 9 |
+
|
| 10 |
+
# Manually defined clean URL to avoid f-string errors
|
| 11 |
+
source_url = "https://huggingface.co"
|
| 12 |
|
| 13 |
if not token:
|
| 14 |
+
print("β ERROR: Set 'HF_TOKEN' in Space Secrets!")
|
| 15 |
else:
|
| 16 |
api = HfApi(token=token)
|
| 17 |
+
print(f"π Starting Transfer for: {filename}")
|
| 18 |
|
| 19 |
try:
|
| 20 |
+
# 2. Use the 'run_as_future' or standard upload with the stream
|
| 21 |
with requests.get(source_url, stream=True) as r:
|
| 22 |
r.raise_for_status()
|
| 23 |
|
| 24 |
+
# 3. Upload using the raw stream
|
|
|
|
| 25 |
api.upload_file(
|
| 26 |
+
path_or_fileobj=r.raw,
|
| 27 |
path_in_repo=filename,
|
| 28 |
repo_id=dest_repo,
|
| 29 |
repo_type="dataset",
|
| 30 |
+
commit_message=f"Direct cloud transfer of {filename}"
|
| 31 |
)
|
| 32 |
|
| 33 |
+
print(f"β
DONE! File is now in {dest_repo}")
|
| 34 |
+
|
| 35 |
except Exception as e:
|
| 36 |
print(f"β Transfer Failed: {e}")
|
| 37 |
+
print("Tip: If it says 'Connection Reset', the file is too big for a basic stream.")
|