kz209 commited on
Commit
27294fd
·
1 Parent(s): 6639e76
.github/workflows/data_collection_trigger.yml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Daily Data Collection Trigger
2
+
3
+ on:
4
+ schedule:
5
+ # Runs every day at 01:00 UTC (9 AM Beijing Time)
6
+ - cron: '0 1 * * *'
7
+ workflow_dispatch:
8
+ # Allows manual triggering from the GitHub Actions tab
9
+
10
+ jobs:
11
+ trigger_space:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Send trigger to Hugging Face Space
15
+ env:
16
+ HF_SPACE_URL: ${{ secrets.HF_SPACE_URL }}
17
+ HF_RUN_KEY: ${{ secrets.HF_RUN_KEY }}
18
+ run: |
19
+ echo "Attempting to trigger data collection at Hugging Face Space: $HF_SPACE_URL"
20
+ response=$(curl -X POST \
21
+ -H "Content-Type: application/json" \
22
+ -d "{\"secret_key\": \"$HF_RUN_KEY\"}" \
23
+ "${HF_SPACE_URL}/run_collector")
24
+
25
+ echo "Response from Space:"
26
+ echo "$response"
27
+
28
+ if echo "$response" | grep -q "鉴权失败:暗号错误!"; then
29
+ echo "Error: Authentication failed. Check HF_RUN_KEY secret."
30
+ exit 1
31
+ elif echo "$response" | grep -q "运行出错"; then
32
+ echo "Error: Script execution failed on Space. Check Space logs."
33
+ exit 1
34
+ else
35
+ echo "Successfully triggered data collection."
36
+ fi
app.py CHANGED
@@ -24,7 +24,7 @@ def run_shell_script(secret_key):
24
  # capture_output=True 可以让我们看到脚本输出的日志
25
  try:
26
  result = subprocess.run(
27
- ["./myscript.sh"],
28
  shell=True,
29
  capture_output=True,
30
  text=True
@@ -36,6 +36,13 @@ def run_shell_script(secret_key):
36
  return f"⚠️ 运行出错: {str(e)}"
37
 
38
 
 
 
 
 
 
 
 
39
  # ==========================================
40
  # 1. Data Reading Engine
41
  # ==========================================
 
24
  # capture_output=True 可以让我们看到脚本输出的日志
25
  try:
26
  result = subprocess.run(
27
+ ["./gpu_info_collector.sh"],
28
  shell=True,
29
  capture_output=True,
30
  text=True
 
36
  return f"⚠️ 运行出错: {str(e)}"
37
 
38
 
39
+ # Expose the script running function as an API endpoint
40
+ api = gr.API()
41
+
42
+ @api.post("/run_collector")
43
+ def run_collector_api(secret_key: str):
44
+ return run_shell_script(secret_key)
45
+
46
  # ==========================================
47
  # 1. Data Reading Engine
48
  # ==========================================