meg HF Staff commited on
Commit
92305c2
·
verified ·
1 Parent(s): ef08818

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from fastapi import FastAPI
3
  from huggingface_hub import HfApi
 
4
 
5
  TOKEN = os.environ.get("BULK_ENERGY_TOKEN")
6
  API = HfApi(token=TOKEN)
@@ -8,6 +9,28 @@ API = HfApi(token=TOKEN)
8
  REPO_ID = "AIEnergyScore/BulkCalcSpace"
9
  app = FastAPI()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  @app.get("/")
12
  def start_train():
13
  model_file = open("models.txt", "r+").readlines()
@@ -25,7 +48,10 @@ def start_train():
25
  model = model.strip()
26
  for task in task_file:
27
  task = task.strip()
28
- os.system(f"./entrypoint.sh {REPO_ID} {model} {task} {hardware}")
 
 
 
29
  #space_variables = API.get_space_variables(repo_id=REPO_ID)
30
  #if 'STATUS' not in space_variables or space_variables['STATUS'] != 'COMPUTING':
31
  # print("Beginning processing.")
 
1
  import os
2
  from fastapi import FastAPI
3
  from huggingface_hub import HfApi
4
+ import time
5
 
6
  TOKEN = os.environ.get("BULK_ENERGY_TOKEN")
7
  API = HfApi(token=TOKEN)
 
9
  REPO_ID = "AIEnergyScore/BulkCalcSpace"
10
  app = FastAPI()
11
 
12
+ def check_for_traceback(run_dir):
13
+ # run_dir="./runs/${experiment_name}/${backend_model}/${now}"
14
+ found_error = False
15
+ error_message = ""
16
+ try:
17
+ # Read error message
18
+ with open(f"{run_dir}/error.log", 'r') as f:
19
+ # There may be a better way to do this that finds the
20
+ # index of Traceback, then prints from there : end-of-file index (the file length-1).
21
+ for line in f:
22
+ # Question: Do we even need to check for this? The presence of the
23
+ # error file, or at least a non-empty one,
24
+ # means there's been an error, no?
25
+ if 'Traceback (most recent call last):' in line:
26
+ found_error = True
27
+ if found_error:
28
+ error_message += line
29
+ except FileNotFoundError as e:
30
+ # When does this happen?
31
+ print(f"Could not find {run_dir}/error.log")
32
+ return error_message
33
+
34
  @app.get("/")
35
  def start_train():
36
  model_file = open("models.txt", "r+").readlines()
 
48
  model = model.strip()
49
  for task in task_file:
50
  task = task.strip()
51
+ # Create the name of the directory for output.
52
+ now = time.time()
53
+ run_dir = f"/runs/${task}/${model}/${now}"
54
+ os.system(f"./entrypoint.sh {REPO_ID} {model} {task} {hardware} {run_dir}")
55
  #space_variables = API.get_space_variables(repo_id=REPO_ID)
56
  #if 'STATUS' not in space_variables or space_variables['STATUS'] != 'COMPUTING':
57
  # print("Beginning processing.")