ThongCoder commited on
Commit
6ec3072
·
verified ·
1 Parent(s): 700eb8c

Update misc.py

Browse files
Files changed (1) hide show
  1. misc.py +30 -22
misc.py CHANGED
@@ -48,27 +48,35 @@ def log_pair(pair):
48
  with open('public/pair.txt', 'at+') as f:
49
  f.write(pair + '\n')
50
 
51
- def trigger_push(amount):
52
- token = os.getenv('GITHUB_PAT')
53
- repo = "ThongAccount/hf-dataset-pusher"
54
- workflow = "update.yml"
55
 
56
- url = f"https://api.github.com/repos/{repo}/actions/workflows/{workflow}/dispatches"
57
- headers = {
58
- "Accept": "application/vnd.github+json",
59
- "Authorization": f"Bearer {token}",
60
- "User-Agent": "hf-dataset-pusher",
61
- "X-GitHub-Api-Version": "2022-11-28"
62
- }
63
- data = {"ref": "main",
64
- "inputs": {
65
- "base_url": "https://thongcoder-infinite-craft-searcher.hf.space",
66
- "amount": amount
67
- }
68
- }
69
 
70
- resp = requests.post(url, headers=headers, json=data)
71
- if resp.ok:
72
- print("✅ Triggered GitHub Action successfully.")
73
- else:
74
- print(f"❌ Failed to trigger Action: {resp.status_code} → {resp.text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  with open('public/pair.txt', 'at+') as f:
49
  f.write(pair + '\n')
50
 
51
+ def trigger_push(n):
52
+ env["HF_HOME"] = "/tmp/hf_cache"
53
+ env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
54
+ env["TMPDIR"] = "/tmp"
55
 
56
+ os.makedirs(env["HF_HOME"], exist_ok=True)
57
+ os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
58
+ os.makedirs(env["TMPDIR"], exist_ok=True)
 
 
 
 
 
 
 
 
 
 
59
 
60
+ cwd = "/tmp"
61
+ os.makedirs(cwd, exist_ok=True)
62
+
63
+ repo_id = 'ThongCoder/infinite-craft'
64
+ local_path = 'db/cache.sqlite'
65
+ path_in_repo = 'cache.sqlite'
66
+ repo_type = 'dataset'
67
+
68
+ cmd = [
69
+ "hf", "upload",
70
+ repo_id,
71
+ local_path,
72
+ path_in_repo,
73
+ "--repo-type", repo_type,
74
+ ]
75
+
76
+ process = subprocess.Popen(
77
+ cmd,
78
+ env=env,
79
+ text=True,
80
+ cwd=cwd,
81
+ )
82
+ process.wait()