Spaces:
Paused
Paused
| 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() | |
| 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() | |
| print(f"Hardware is {hardware}") | |
| curr_runtime = API.get_space_runtime(repo_id=REPO_ID) | |
| print(f"Current hardware is {curr_runtime}") | |
| if curr_runtime != hardware: | |
| print("Trying to switch.") | |
| 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']} |