Update flask_server.py

This commit is contained in:
MacRimi
2025-10-07 20:26:05 +02:00
parent 3b87c078f4
commit 562df0f48f

View File

@@ -1635,6 +1635,9 @@ def get_detailed_gpu_info(gpu):
output_lines.append(line) output_lines.append(line)
output = ''.join(output_lines) output = ''.join(output_lines)
if len(output_lines) <= 5:
print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}")
# intel_gpu_top -J outputs: [\n{\n...\n},\n{\n...\n}\n] # intel_gpu_top -J outputs: [\n{\n...\n},\n{\n...\n}\n]
# We need to find the first complete object inside the array # We need to find the first complete object inside the array
@@ -1642,6 +1645,8 @@ def get_detailed_gpu_info(gpu):
if '[' not in output: if '[' not in output:
continue continue
print(f"[v0] Found array start bracket, total output length: {len(output)}")
# Find the start of the array # Find the start of the array
array_start = output.index('[') array_start = output.index('[')
after_array_start = output[array_start + 1:] after_array_start = output[array_start + 1:]
@@ -1664,12 +1669,16 @@ def get_detailed_gpu_info(gpu):
object_end = i + 1 object_end = i + 1
break break
print(f"[v0] Object parsing: start={object_start}, end={object_end}, brace_count={brace_count}")
if object_start >= 0 and object_end > object_start: if object_start >= 0 and object_end > object_start:
# Extract the first complete JSON object # Extract the first complete JSON object
json_str = after_array_start[object_start:object_end] json_str = after_array_start[object_start:object_end]
print(f"[v0] Extracted JSON string (first 200 chars): {json_str[:200]}")
try: try:
json_data = json.loads(json_str) json_data = json.loads(json_str)
print(f"[v0] Successfully parsed JSON object from intel_gpu_top array") print(f"[v0] Successfully parsed JSON object from intel_gpu_top array")
print(f"[v0] JSON keys: {list(json_data.keys())}")
# Parse frequency data # Parse frequency data
if 'frequency' in json_data: if 'frequency' in json_data:
@@ -2730,7 +2739,8 @@ def api_info():
@app.route('/api/hardware', methods=['GET']) @app.route('/api/hardware', methods=['GET'])
def api_hardware(): def api_hardware():
"""Get comprehensive hardware information""" """Get hardware information"""
try:
hardware_info = get_hardware_info() hardware_info = get_hardware_info()
all_fans = hardware_info.get('sensors', {}).get('fans', []) all_fans = hardware_info.get('sensors', {}).get('fans', [])
@@ -2741,7 +2751,8 @@ def api_hardware():
formatted_data = { formatted_data = {
'cpu': hardware_info.get('cpu', {}), 'cpu': hardware_info.get('cpu', {}),
'motherboard': hardware_info.get('motherboard', {}), 'motherboard': hardware_info.get('motherboard', {}),
'memory_modules': hardware_data.get('memory_modules', []), 'bios': hardware_info.get('bios', {}),
'memory_modules': hardware_info.get('memory_modules', []),
'storage_devices': hardware_info.get('storage_devices', []), 'storage_devices': hardware_info.get('storage_devices', []),
'pci_devices': hardware_info.get('pci_devices', []), 'pci_devices': hardware_info.get('pci_devices', []),
'temperatures': hardware_info.get('sensors', {}).get('temperatures', []), 'temperatures': hardware_info.get('sensors', {}).get('temperatures', []),
@@ -2762,6 +2773,11 @@ def api_hardware():
print(f"[v0] - GPUs: {len(formatted_data['gpus'])} found") print(f"[v0] - GPUs: {len(formatted_data['gpus'])} found")
return jsonify(formatted_data) return jsonify(formatted_data)
except Exception as e:
print(f"[v0] Error in api_hardware: {e}")
import traceback
traceback.print_exc()
return jsonify({'error': str(e)}), 500
@app.route('/api/gpu/<slot>/realtime', methods=['GET']) @app.route('/api/gpu/<slot>/realtime', methods=['GET'])
def api_gpu_realtime(slot): def api_gpu_realtime(slot):