Sudipta Nayak
commited on
Commit
·
04f5d68
1
Parent(s):
5f07b35
no message
Browse files- app/main.py +7 -6
app/main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from fastapi import FastAPI, Request, UploadFile
|
3 |
from fastapi.responses import HTMLResponse, FileResponse
|
4 |
from fastapi.staticfiles import StaticFiles
|
5 |
from fastapi.templating import Jinja2Templates
|
@@ -47,8 +47,8 @@ async def detect_objects(request: Request, file: UploadFile):
|
|
47 |
print('Detect start')
|
48 |
|
49 |
# Run YOLOv7 detection and save output
|
50 |
-
|
51 |
-
"--source", str(input_file_path), "--save-txt", "--save-conf", "--exist-ok", "--project", str(output_file_path)])
|
52 |
|
53 |
print('Detect end')
|
54 |
|
@@ -69,9 +69,10 @@ async def detect_objects(request: Request, file: UploadFile):
|
|
69 |
# return StreamingResponse(open(output_file, "rb"), media_type="video/mp4")
|
70 |
|
71 |
|
72 |
-
except
|
73 |
-
|
74 |
-
|
|
|
75 |
|
76 |
|
77 |
|
|
|
1 |
import os
|
2 |
+
from fastapi import FastAPI, Request, UploadFile, HTTPException
|
3 |
from fastapi.responses import HTMLResponse, FileResponse
|
4 |
from fastapi.staticfiles import StaticFiles
|
5 |
from fastapi.templating import Jinja2Templates
|
|
|
47 |
print('Detect start')
|
48 |
|
49 |
# Run YOLOv7 detection and save output
|
50 |
+
subprocess.run(["python", "app/detect.py", "--conf", "0.5", "--img-size", "640", "--weights", "app/model/best.pt", "--no-trace",
|
51 |
+
"--source", str(input_file_path), "--save-txt", "--save-conf", "--exist-ok", "--project", str(output_file_path)], check=True)
|
52 |
|
53 |
print('Detect end')
|
54 |
|
|
|
69 |
# return StreamingResponse(open(output_file, "rb"), media_type="video/mp4")
|
70 |
|
71 |
|
72 |
+
except subprocess.CalledProcessError as e:
|
73 |
+
# Handle subprocess error (e.g., log the error, return an error response)
|
74 |
+
print(f"Subprocess error: {e}")
|
75 |
+
raise HTTPException(status_code=500, detail="Subprocess error")
|
76 |
|
77 |
|
78 |
|