Sudipta Nayak
commited on
Commit
·
b3619b5
1
Parent(s):
5918063
issue fix -3
Browse files- app/main.py +7 -6
app/main.py
CHANGED
@@ -35,26 +35,27 @@ async def root(request: Request):
|
|
35 |
async def detect_objects(request: Request, file: UploadFile):
|
36 |
try:
|
37 |
|
38 |
-
print('File name:', file.filename
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
# Save the uploaded file
|
44 |
-
with open(
|
45 |
file.write(file.file.read())
|
46 |
|
47 |
print('Detect start')
|
48 |
|
49 |
# Run YOLOv7 detection and save output
|
50 |
-
subprocess.run(["python", "detect.py", "--conf", "0.5", "--img-size", "640", "--weights", "app/model/best.pt",
|
|
|
51 |
|
52 |
print('Detect end')
|
53 |
|
54 |
# Render HTML using Jinja2Templates
|
55 |
return templates.TemplateResponse(
|
56 |
"result.html",
|
57 |
-
{"request": request, "original_image":
|
58 |
)
|
59 |
# return templates.TemplateResponse("index.html", {"request": request})
|
60 |
|
|
|
35 |
async def detect_objects(request: Request, file: UploadFile):
|
36 |
try:
|
37 |
|
38 |
+
print('File name:', file.filename)
|
39 |
|
40 |
+
input_file_path = f"app/static/{file.filename}"
|
41 |
+
output_file_path = f"app/static/output/{file.filename}"
|
42 |
|
43 |
# Save the uploaded file
|
44 |
+
with open(input_file_path, "wb") as file:
|
45 |
file.write(file.file.read())
|
46 |
|
47 |
print('Detect start')
|
48 |
|
49 |
# Run YOLOv7 detection and save output
|
50 |
+
subprocess.run(["python", "detect.py", "--conf", "0.5", "--img-size", "640", "--weights", "app/model/best.pt",
|
51 |
+
"--source", str(input_file_path), "--save-txt", "--save-conf", "--exist-ok", "--project", str(output_file_path)])
|
52 |
|
53 |
print('Detect end')
|
54 |
|
55 |
# Render HTML using Jinja2Templates
|
56 |
return templates.TemplateResponse(
|
57 |
"result.html",
|
58 |
+
{"request": request, "original_image": str(input_file_path), "output_image": str(output_file_path)},
|
59 |
)
|
60 |
# return templates.TemplateResponse("index.html", {"request": request})
|
61 |
|