youssef
commited on
Commit
·
e927231
1
Parent(s):
9a80e6e
timing
Browse files- src/app.py +25 -4
src/app.py
CHANGED
@@ -3,6 +3,7 @@ from video_processor.processor import VideoAnalyzer, get_video_duration_seconds
|
|
3 |
import logging
|
4 |
import torch
|
5 |
import spaces
|
|
|
6 |
|
7 |
# Configure logging
|
8 |
logging.basicConfig(level=logging.INFO)
|
@@ -17,6 +18,8 @@ if torch.cuda.is_available():
|
|
17 |
|
18 |
@spaces.GPU
|
19 |
def on_process(video):
|
|
|
|
|
20 |
# Clear all components when starting new processing
|
21 |
yield [
|
22 |
"", # Clear status
|
@@ -34,6 +37,7 @@ def on_process(video):
|
|
34 |
|
35 |
try:
|
36 |
# Initialize analyzer
|
|
|
37 |
yield [
|
38 |
"Initializing video analyzer...",
|
39 |
"",
|
@@ -41,10 +45,12 @@ def on_process(video):
|
|
41 |
]
|
42 |
|
43 |
analyzer = VideoAnalyzer()
|
|
|
|
|
44 |
|
45 |
# Process video
|
46 |
yield [
|
47 |
-
"
|
48 |
"",
|
49 |
gr.update(visible=True)
|
50 |
]
|
@@ -57,16 +63,25 @@ def on_process(video):
|
|
57 |
|
58 |
# Process video segments
|
59 |
yield [
|
60 |
-
f"Processing video... (
|
61 |
"",
|
62 |
gr.update(visible=True)
|
63 |
]
|
64 |
|
65 |
# Process segments and show progress
|
66 |
segments = []
|
|
|
|
|
67 |
for i, segment in enumerate(analyzer.process_video(video)):
|
|
|
68 |
segments.append(segment)
|
|
|
|
|
|
|
69 |
progress = int((i + 1) / total_segments * 100)
|
|
|
|
|
|
|
70 |
|
71 |
# Format current segments
|
72 |
formatted_desc = "### Video Analysis by Segments:\n\n"
|
@@ -74,13 +89,19 @@ def on_process(video):
|
|
74 |
formatted_desc += f"**[{seg['timestamp']}]** {seg['description']}\n\n"
|
75 |
|
76 |
yield [
|
77 |
-
f"Processing segments... {progress}% complete"
|
|
|
|
|
|
|
78 |
formatted_desc,
|
79 |
gr.update(visible=True)
|
80 |
]
|
81 |
|
|
|
82 |
yield [
|
83 |
-
"Processing complete
|
|
|
|
|
84 |
formatted_desc,
|
85 |
gr.update(visible=True)
|
86 |
]
|
|
|
3 |
import logging
|
4 |
import torch
|
5 |
import spaces
|
6 |
+
import time
|
7 |
|
8 |
# Configure logging
|
9 |
logging.basicConfig(level=logging.INFO)
|
|
|
18 |
|
19 |
@spaces.GPU
|
20 |
def on_process(video):
|
21 |
+
start_time = time.time()
|
22 |
+
|
23 |
# Clear all components when starting new processing
|
24 |
yield [
|
25 |
"", # Clear status
|
|
|
37 |
|
38 |
try:
|
39 |
# Initialize analyzer
|
40 |
+
init_start = time.time()
|
41 |
yield [
|
42 |
"Initializing video analyzer...",
|
43 |
"",
|
|
|
45 |
]
|
46 |
|
47 |
analyzer = VideoAnalyzer()
|
48 |
+
init_time = time.time() - init_start
|
49 |
+
logger.info(f"Initialization took {init_time:.2f} seconds")
|
50 |
|
51 |
# Process video
|
52 |
yield [
|
53 |
+
f"Model initialized in {init_time:.2f}s. Starting analysis...",
|
54 |
"",
|
55 |
gr.update(visible=True)
|
56 |
]
|
|
|
63 |
|
64 |
# Process video segments
|
65 |
yield [
|
66 |
+
f"Processing video... (Will analyze {total_segments} segments)",
|
67 |
"",
|
68 |
gr.update(visible=True)
|
69 |
]
|
70 |
|
71 |
# Process segments and show progress
|
72 |
segments = []
|
73 |
+
total_processing_time = 0
|
74 |
+
|
75 |
for i, segment in enumerate(analyzer.process_video(video)):
|
76 |
+
segment_start = time.time()
|
77 |
segments.append(segment)
|
78 |
+
segment_time = time.time() - segment_start
|
79 |
+
total_processing_time += segment_time
|
80 |
+
|
81 |
progress = int((i + 1) / total_segments * 100)
|
82 |
+
avg_time_per_segment = total_processing_time / (i + 1)
|
83 |
+
remaining_segments = total_segments - (i + 1)
|
84 |
+
estimated_remaining = remaining_segments * avg_time_per_segment
|
85 |
|
86 |
# Format current segments
|
87 |
formatted_desc = "### Video Analysis by Segments:\n\n"
|
|
|
89 |
formatted_desc += f"**[{seg['timestamp']}]** {seg['description']}\n\n"
|
90 |
|
91 |
yield [
|
92 |
+
f"Processing segments... {progress}% complete\n" +
|
93 |
+
f"Segment {i+1}/{total_segments} processed in {segment_time:.2f}s\n" +
|
94 |
+
f"Average time per segment: {avg_time_per_segment:.2f}s\n" +
|
95 |
+
f"Estimated time remaining: {estimated_remaining:.2f}s",
|
96 |
formatted_desc,
|
97 |
gr.update(visible=True)
|
98 |
]
|
99 |
|
100 |
+
total_time = time.time() - start_time
|
101 |
yield [
|
102 |
+
f"Processing complete!\n" +
|
103 |
+
f"Total processing time: {total_time:.2f}s\n" +
|
104 |
+
f"Average time per segment: {total_processing_time/total_segments:.2f}s",
|
105 |
formatted_desc,
|
106 |
gr.update(visible=True)
|
107 |
]
|