File size: 1,532 Bytes
13c6f75
 
 
 
 
 
 
 
 
 
 
 
8eccf98
 
 
 
 
a782adf
8eccf98
4402217
8eccf98
4402217
8eccf98
 
 
 
 
 
b4bebbc
 
 
 
8eccf98
b4bebbc
8eccf98
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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()
        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']}