koenverhagen commited on
Commit
0ab5cef
·
1 Parent(s): 8fa8335

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +10 -11
server.py CHANGED
@@ -73,7 +73,7 @@ async def resolution(request : Request, background_tasks: BackgroundTasks, respo
73
 
74
  image = io.BytesIO(await data.read())
75
  image.seek(0)
76
-
77
  result = cardtagger(image.read())
78
 
79
  background_tasks.add_task(delete_old_files)
@@ -85,18 +85,17 @@ async def resolution(request : Request, background_tasks: BackgroundTasks, respo
85
  response.status_code = 401
86
  return response
87
 
88
- @app.get("/nividia")
89
  def check_gpu_usage():
90
  try:
91
- output = subprocess.check_output("nvidia-smi", shell=True).decode("utf-8")
92
- # lines = output.split('\n')
93
- # usage=[]
94
- # for line in lines:
95
- # if '%' in line:
96
- # usage.append(line.strip().split(' ')[-2])
97
- #
98
- # print("GPU is not being used.")
99
- return output
100
  except subprocess.CalledProcessError:
101
  print("Nvidia-smi command not found, please check if the NVIDIA drivers are installed.")
102
  return "Nvidia-smi command not found, please check if the NVIDIA drivers are installed."
 
73
 
74
  image = io.BytesIO(await data.read())
75
  image.seek(0)
76
+ background_tasks.add_task(check_gpu_usage)
77
  result = cardtagger(image.read())
78
 
79
  background_tasks.add_task(delete_old_files)
 
85
  response.status_code = 401
86
  return response
87
 
88
+
89
  def check_gpu_usage():
90
  try:
91
+ while True:
92
+ output = subprocess.check_output("nvidia-smi", shell=True).decode("utf-8")
93
+ lines = output.split('\n')
94
+
95
+ for line in lines:
96
+ if '%' in line:
97
+ print(line.strip().split(' ')[-2])
98
+ return
 
99
  except subprocess.CalledProcessError:
100
  print("Nvidia-smi command not found, please check if the NVIDIA drivers are installed.")
101
  return "Nvidia-smi command not found, please check if the NVIDIA drivers are installed."