Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,35 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
# Name the secret: HF_TOKEN
|
| 6 |
token = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
if not token:
|
| 9 |
-
print("β Error:
|
| 10 |
else:
|
| 11 |
api = HfApi(token=token)
|
| 12 |
-
|
| 13 |
-
# Configuration
|
| 14 |
-
source_url = "https://huggingface.co/nold/starcoder2-15b-GGUF/resolve/main/starcoder2-15b_Q4_K_M.gguf"
|
| 15 |
-
filename = "starcoder2-15b-instruct-v0.1-Q4_K_M.gguf"
|
| 16 |
-
dest_repo = "AIDev07/AIModelsLoaded"
|
| 17 |
-
|
| 18 |
-
print(f"π Starting server-side transfer of {filename}...")
|
| 19 |
|
| 20 |
try:
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
except Exception as e:
|
| 31 |
-
print(f"β Failed: {e}")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
from huggingface_hub import HfApi
|
| 4 |
|
| 5 |
+
# 1. Get Token from Secrets
|
|
|
|
| 6 |
token = os.getenv("HF_TOKEN")
|
| 7 |
+
dest_repo = "AIDev07/AIModelsLoaded"
|
| 8 |
+
filename = "starcoder2-15b-instruct-v0.1-Q4_K_M.gguf"
|
| 9 |
+
# Use the direct download URL
|
| 10 |
+
source_url = f"https://huggingface.co{filename}"
|
| 11 |
|
| 12 |
if not token:
|
| 13 |
+
print("β Error: Add your 'HF_TOKEN' to the Space Secrets!")
|
| 14 |
else:
|
| 15 |
api = HfApi(token=token)
|
| 16 |
+
print(f"π Starting Stream Transfer for: {filename}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
# 2. Open a streaming connection to the source file
|
| 20 |
+
with requests.get(source_url, stream=True) as r:
|
| 21 |
+
r.raise_for_status()
|
| 22 |
+
|
| 23 |
+
# 3. Upload the stream directly to your dataset
|
| 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"Streamed upload of {filename}"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
print(f"β
SUCCESS! {filename} is now in {dest_repo}")
|
| 34 |
except Exception as e:
|
| 35 |
+
print(f"β Transfer Failed: {e}")
|