Spaces:
Sleeping
Sleeping
koenverhagen
commited on
Commit
•
efbc12f
1
Parent(s):
5f92fe7
Update server.py
Browse files
server.py
CHANGED
@@ -3,6 +3,7 @@ from pydantic import BaseModel
|
|
3 |
from fastapi.responses import FileResponse
|
4 |
from starlette.middleware.cors import CORSMiddleware
|
5 |
from starlette.responses import RedirectResponse
|
|
|
6 |
|
7 |
from cardtagger import cardtagger
|
8 |
|
@@ -84,6 +85,21 @@ async def resolution(request : Request, background_tasks: BackgroundTasks, respo
|
|
84 |
response.status_code = 401
|
85 |
return response
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
|
89 |
#uvicorn server:app --host 0.0.0.0 --port 5050 --workers 4
|
|
|
3 |
from fastapi.responses import FileResponse
|
4 |
from starlette.middleware.cors import CORSMiddleware
|
5 |
from starlette.responses import RedirectResponse
|
6 |
+
import subprocess
|
7 |
|
8 |
from cardtagger import cardtagger
|
9 |
|
|
|
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 |
+
for line in lines:
|
94 |
+
if '%' in line:
|
95 |
+
usage = line.strip().split(' ')[-2]
|
96 |
+
print(f"GPU is being used, usage: {usage}")
|
97 |
+
return
|
98 |
+
print("GPU is not being used.")
|
99 |
+
except subprocess.CalledProcessError:
|
100 |
+
print("Nvidia-smi command not found, please check if the NVIDIA drivers are installed.")
|
101 |
+
|
102 |
+
|
103 |
|
104 |
|
105 |
#uvicorn server:app --host 0.0.0.0 --port 5050 --workers 4
|