BulkCalcSpace / app.py
meg's picture
meg HF Staff
Update app.py
8eccf98 verified
raw
history blame
1.4 kB
import os
from fastapi import FastAPI
from huggingface_hub import HfApi
TOKEN = os.environ.get("BULK_ENERGY_TOKEN")
API = HfApi(token=TOKEN)
REPO_ID = "AIEnergyScore/BulkCalcSpace"
app = FastAPI()
@app.get("/")
def start_train():
model_file = open("models.txt", "r+").readlines()
task_file = open("tasks.txt", "r+").readlines()
hardware_file = open("hardware.txt", "r+").readlines()
for hardware in hardware_file:
hardware = hardware.strip()
curr_runtime = API.get_space_runtime(repo_id=REPO_ID)
if curr_runtime != hardware:
API.request_space_hardware(repo_id=REPO_ID, hardware=hardware)
for model in model_file:
model = model.strip()
for task in task_file:
task = task.strip()
os.system(f"./entrypoint.sh {REPO_ID} {model} {task} {hardware}")
#space_variables = API.get_space_variables(repo_id=REPO_ID)
#if 'STATUS' not in space_variables or space_variables['STATUS'] != 'COMPUTING':
# print("Beginning processing.")
# API.add_space_variable(repo_id=REPO_ID, key='STATUS', value='COMPUTING')
#os.system(f"./entrypoint.sh {REPO_ID} {model} {task} {hardware}")
#API.add_space_variable(repo_id=REPO_ID, key='STATUS', value='NOT_COMPUTING')
print("Pausing space")
API.pause_space(REPO_ID)
return {"Status": "Done"}#space_variables['STATUS']}