Sudipta Nayak commited on
Commit
9c02022
·
1 Parent(s): cb6b69f

Issue fix-2

Browse files
Files changed (2) hide show
  1. app/main.py +13 -14
  2. app/templates/index.html +1 -1
app/main.py CHANGED
@@ -32,30 +32,29 @@ async def root(request: Request):
32
  @app.post("/detect/", response_class=HTMLResponse)
33
  async def detect_objects(request: Request, file: UploadFile):
34
  try:
35
- # print('Item:', item)
36
-
37
- # print('File name:', item.file.filename)
38
 
39
- # input_file = f"uploads/{item.file.filename}"
40
- # output_file = f"static/output/{item.file.filename}"
41
 
42
- # # Save the uploaded file
43
- # with open(input_file, "wb") as file:
44
- # file.write(item.file.file.read())
45
 
46
  print('Detect start')
47
 
48
  # Run YOLOv7 detection and save output
49
- # subprocess.run(["python", "detect.py", "--conf", "0.5", "--img-size", "640", "--weights", "app/model/best.pt", "--source", input_file, "--save-txt", "--save-conf", "--exist-ok", "--project", output_file])
50
 
51
  print('Detect end')
52
 
53
  # Render HTML using Jinja2Templates
54
- # return templates.TemplateResponse(
55
- # "result.html",
56
- # {"request": request, "original_image": f"/static/{item.file.filename}", "output_image": f"/static/output/{item.file.filename}"},
57
- # )
58
- return templates.TemplateResponse("index.html", {"request": request})
59
 
60
  except Exception as e:
61
  logging.error(f"Error in /detect endpoint: {str(e)}")
 
32
  @app.post("/detect/", response_class=HTMLResponse)
33
  async def detect_objects(request: Request, file: UploadFile):
34
  try:
35
+
36
+ print('File name:', file.filename)
 
37
 
38
+ input_file = f"uploads/{file.filename}"
39
+ output_file = f"static/output/{file.filename}"
40
 
41
+ # Save the uploaded file
42
+ with open(input_file, "wb") as file:
43
+ file.write(file.file.read())
44
 
45
  print('Detect start')
46
 
47
  # Run YOLOv7 detection and save output
48
+ subprocess.run(["python", "detect.py", "--conf", "0.5", "--img-size", "640", "--weights", "app/model/best.pt", "--source", input_file, "--save-txt", "--save-conf", "--exist-ok", "--project", output_file])
49
 
50
  print('Detect end')
51
 
52
  # Render HTML using Jinja2Templates
53
+ return templates.TemplateResponse(
54
+ "result.html",
55
+ {"request": request, "original_image": f"/static/{file.filename}", "output_image": f"/static/output/{file.filename}"},
56
+ )
57
+ # return templates.TemplateResponse("index.html", {"request": request})
58
 
59
  except Exception as e:
60
  logging.error(f"Error in /detect endpoint: {str(e)}")
app/templates/index.html CHANGED
@@ -7,7 +7,7 @@
7
  <title>Object Detection App</title>
8
  </head>
9
  <body>
10
- <h1>Welcome to Object Detection App</h1>
11
  <form action="/detect/" method="post" enctype="multipart/form-data">
12
  <label for="file">Upload an Image or Video :</label>
13
  <input type="file" id="file" name="file" accept=".jpg, .jpeg, .png, .mp4" required>
 
7
  <title>Object Detection App</title>
8
  </head>
9
  <body>
10
+ <h1>Object Detection App</h1>
11
  <form action="/detect/" method="post" enctype="multipart/form-data">
12
  <label for="file">Upload an Image or Video :</label>
13
  <input type="file" id="file" name="file" accept=".jpg, .jpeg, .png, .mp4" required>