AIDev07 commited on
Commit
b124a22
Β·
verified Β·
1 Parent(s): 436f4ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -1,31 +1,35 @@
1
  import os
 
2
  from huggingface_hub import HfApi
3
 
4
- # Use Secrets (Settings > Variables and secrets > New secret)
5
- # Name the secret: HF_TOKEN
6
  token = os.getenv("HF_TOKEN")
 
 
 
 
7
 
8
  if not token:
9
- print("❌ Error: HF_TOKEN secret not found in Space settings!")
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
- # This tells HF to grab the file from the URL and save it to your dataset
22
- api.upload_file(
23
- path_or_fileobj=source_url, # The URL acts as the source
24
- path_in_repo=filename,
25
- repo_id=dest_repo,
26
- repo_type="dataset",
27
- commit_message=f"Direct transfer of {filename}"
28
- )
29
- print("βœ… Success! Check your dataset now.")
 
 
 
 
 
 
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}")