Sudipta Nayak
commited on
Commit
·
2244f4f
1
Parent(s):
4fc145a
video file related changes
Browse files- app/main.py +6 -1
- app/templates/result.html +16 -3
app/main.py
CHANGED
@@ -5,6 +5,7 @@ from fastapi.staticfiles import StaticFiles
|
|
5 |
from fastapi.templating import Jinja2Templates
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
from pydantic import BaseModel
|
|
|
8 |
|
9 |
import subprocess
|
10 |
from pathlib import Path
|
@@ -38,6 +39,10 @@ async def detect_objects(request: Request, file: UploadFile):
|
|
38 |
with open(input_file_path, "wb") as input_file:
|
39 |
input_file.write(await file.read())
|
40 |
|
|
|
|
|
|
|
|
|
41 |
print('Detect start')
|
42 |
|
43 |
# Run YOLOv7 detection and save output
|
@@ -55,7 +60,7 @@ async def detect_objects(request: Request, file: UploadFile):
|
|
55 |
# Render HTML using Jinja2Templates
|
56 |
return templates.TemplateResponse(
|
57 |
"result.html",
|
58 |
-
{"request": request, "output_image": str(output_image_path)}
|
59 |
)
|
60 |
|
61 |
|
|
|
5 |
from fastapi.templating import Jinja2Templates
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
from pydantic import BaseModel
|
8 |
+
import mimetypes # For determining file type
|
9 |
|
10 |
import subprocess
|
11 |
from pathlib import Path
|
|
|
39 |
with open(input_file_path, "wb") as input_file:
|
40 |
input_file.write(await file.read())
|
41 |
|
42 |
+
# Determine the file type
|
43 |
+
file_type, _ = mimetypes.guess_type(file.filename)
|
44 |
+
is_video = file_type and file_type.startswith('video')
|
45 |
+
|
46 |
print('Detect start')
|
47 |
|
48 |
# Run YOLOv7 detection and save output
|
|
|
60 |
# Render HTML using Jinja2Templates
|
61 |
return templates.TemplateResponse(
|
62 |
"result.html",
|
63 |
+
{"request": request, "output_image": str(output_image_path), "is_video": is_video}
|
64 |
)
|
65 |
|
66 |
|
app/templates/result.html
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
display: flex;
|
11 |
flex-direction: column;
|
12 |
align-items: center;
|
13 |
-
justify-content: flex-start;
|
14 |
height: 100vh;
|
15 |
margin: 0;
|
16 |
}
|
@@ -28,13 +28,25 @@
|
|
28 |
height: auto;
|
29 |
display: none; /* Initially hidden until loaded */
|
30 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
</style>
|
32 |
<script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
|
33 |
<script type="text/javascript">
|
34 |
function onOpenCvReady() {
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
document.getElementById("loading").style.display = "none"; // Hide the loading icon
|
37 |
-
document.getElementById("output").style.display = "block"; // Show the output image
|
38 |
}
|
39 |
|
40 |
// Function to show loading icon while waiting for response
|
@@ -53,5 +65,6 @@
|
|
53 |
<br/>
|
54 |
<div id="loading">Loading...</div>
|
55 |
<img id="output"/>
|
|
|
56 |
</body>
|
57 |
</html>
|
|
|
10 |
display: flex;
|
11 |
flex-direction: column;
|
12 |
align-items: center;
|
13 |
+
justify-content: flex-start; /* Align content at the top */
|
14 |
height: 100vh;
|
15 |
margin: 0;
|
16 |
}
|
|
|
28 |
height: auto;
|
29 |
display: none; /* Initially hidden until loaded */
|
30 |
}
|
31 |
+
|
32 |
+
#output-video {
|
33 |
+
max-width: 100%;
|
34 |
+
height: auto;
|
35 |
+
display: none; /* Initially hidden until loaded */
|
36 |
+
}
|
37 |
</style>
|
38 |
<script async src="https://docs.opencv.org/master/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
|
39 |
<script type="text/javascript">
|
40 |
function onOpenCvReady() {
|
41 |
+
var isVideo = "{{ is_video }}"; // Assuming you pass a variable indicating whether it's a video
|
42 |
+
if (isVideo === "true") {
|
43 |
+
document.getElementById("output-video").src = "{{ output_image }}";
|
44 |
+
document.getElementById("output-video").style.display = "block"; // Show the output video
|
45 |
+
} else {
|
46 |
+
document.getElementById("output").src = "{{ output_image }}";
|
47 |
+
document.getElementById("output").style.display = "block"; // Show the output image
|
48 |
+
}
|
49 |
document.getElementById("loading").style.display = "none"; // Hide the loading icon
|
|
|
50 |
}
|
51 |
|
52 |
// Function to show loading icon while waiting for response
|
|
|
65 |
<br/>
|
66 |
<div id="loading">Loading...</div>
|
67 |
<img id="output"/>
|
68 |
+
<video id="output-video" controls></video>
|
69 |
</body>
|
70 |
</html>
|