32 lines
761 B
Plaintext
32 lines
761 B
Plaintext
# -*- coding:utf-8 -*-
|
|
# GET /api/status - ASR服务状态
|
|
|
|
import subprocess
|
|
import json
|
|
|
|
result = {
|
|
'service': 'asr-transcription',
|
|
'model': 'faster-whisper-large-v3-turbo-ct2',
|
|
'gpu_id': 6,
|
|
'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)
|