AIDev07 commited on
Commit
77c4d7d
Β·
verified Β·
1 Parent(s): b124a22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -2,34 +2,36 @@ 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}")
 
 
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.")