33 lines
783 B
Plaintext
33 lines
783 B
Plaintext
# -*- coding:utf-8 -*-
|
|
# GET /api/status - Real-ESRGAN服务状态
|
|
|
|
import subprocess
|
|
import json
|
|
|
|
result = {
|
|
'service': 'realesrgan-video-upscale',
|
|
'model': 'RealESRGAN_x2plus',
|
|
'gpu_id': 5,
|
|
'scale_factor': 2,
|
|
'gpus': []
|
|
}
|
|
|
|
try:
|
|
out = subprocess.check_output(
|
|
['nvidia-smi', '--query-gpu=index,utilization.gpu,memory.used,memory.total',
|
|
'--format=csv,noheader,nounits'],
|
|
timeout=5
|
|
).decode().strip()
|
|
for line in out.split('\n'):
|
|
parts = [p.strip() for p in line.split(',')]
|
|
result['gpus'].append({
|
|
'id': int(parts[0]),
|
|
'util': int(parts[1]),
|
|
'mem_used': int(parts[2]),
|
|
'mem_total': int(parts[3])
|
|
})
|
|
except Exception:
|
|
pass
|
|
|
|
return json.dumps(result)
|