from subprocess import check_output
import json

gpu_usage = check_output(["nvidia-smi", "--query-gpu=utilization.gpu", "--format=csv,noheader,nounits"])

gpu_usage = gpu_usage.decode('utf-8').replace("\n",'')

return_json = {
    "text":gpu_usage,
    "alt":"GPU_PERCENT",
    "tooltip":"GPU percentage",
    "class":"gpu_class",
    "percentage":int(gpu_usage)
}

print(json.dumps(return_json))