Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -134,7 +134,7 @@ def check_condition(prompt, base64Frames):
|
|
134 |
|
135 |
|
136 |
# Function to process video clip and update the chatbot
|
137 |
-
def process_clip(prompt, frames, chatbot):
|
138 |
# Print current time in Israel
|
139 |
israel_tz = pytz.timezone('Asia/Jerusalem')
|
140 |
start_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
@@ -147,9 +147,10 @@ def process_clip(prompt, frames, chatbot):
|
|
147 |
|
148 |
if api_response["condition_met"] == True:
|
149 |
finish_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
150 |
-
video_clip_path = encode_to_video_fast(frames, fps)
|
|
|
151 |
chatbot.append(((video_clip_path,), None))
|
152 |
-
chatbot.append((f"Time: {start_time}\nDetails: {api_response.get('details', '')}", None))
|
153 |
|
154 |
frame_paths = []
|
155 |
for i, base64_frame in enumerate(base64Frames):
|
@@ -176,6 +177,7 @@ def process_clip_from_file(prompt, frames, chatbot, fps, video_path, id):
|
|
176 |
video_clip_path = clip_video_segment_2(video_path, id*LENGTH, LENGTH)
|
177 |
chatbot.append(((video_clip_path,), None))
|
178 |
chatbot.append((f"Event ID: {id+1}\nDetails: {api_response.get('details', '')}", None))
|
|
|
179 |
|
180 |
return chatbot
|
181 |
|
@@ -191,6 +193,7 @@ def analyze_stream(prompt, chatbot):
|
|
191 |
|
192 |
frames = []
|
193 |
start_time = time.time()
|
|
|
194 |
while not stop_capture:
|
195 |
ret, frame = cap.read()
|
196 |
if not ret:
|
@@ -200,9 +203,10 @@ def analyze_stream(prompt, chatbot):
|
|
200 |
# Sample the frames every 5 seconds
|
201 |
if time.time() - start_time >= LENGTH:
|
202 |
# Start a new thread for processing the video clip
|
203 |
-
Thread(target=process_clip, args=(prompt, frames.copy(), chatbot,)).start()
|
204 |
frames = []
|
205 |
start_time = time.time()
|
|
|
206 |
yield chatbot
|
207 |
|
208 |
cap.release()
|
|
|
134 |
|
135 |
|
136 |
# Function to process video clip and update the chatbot
|
137 |
+
def process_clip(prompt, frames, chatbot, id):
|
138 |
# Print current time in Israel
|
139 |
israel_tz = pytz.timezone('Asia/Jerusalem')
|
140 |
start_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
|
|
147 |
|
148 |
if api_response["condition_met"] == True:
|
149 |
finish_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
150 |
+
# video_clip_path = encode_to_video_fast(frames, fps)
|
151 |
+
video_clip_path = clip_video_segment_2("https://uqnmqpvwlbpmdvutucia.supabase.co/storage/v1/object/public/videos_test/junction.mp4?t=2024-12-26T09%3A58%3A11.931Z", id*LENGTH, LENGTH)
|
152 |
chatbot.append(((video_clip_path,), None))
|
153 |
+
chatbot.append((f"ID: {id}. Time: {start_time}\nDetails: {api_response.get('details', '')}", None))
|
154 |
|
155 |
frame_paths = []
|
156 |
for i, base64_frame in enumerate(base64Frames):
|
|
|
177 |
video_clip_path = clip_video_segment_2(video_path, id*LENGTH, LENGTH)
|
178 |
chatbot.append(((video_clip_path,), None))
|
179 |
chatbot.append((f"Event ID: {id+1}\nDetails: {api_response.get('details', '')}", None))
|
180 |
+
yield chatbot
|
181 |
|
182 |
return chatbot
|
183 |
|
|
|
193 |
|
194 |
frames = []
|
195 |
start_time = time.time()
|
196 |
+
id = 0
|
197 |
while not stop_capture:
|
198 |
ret, frame = cap.read()
|
199 |
if not ret:
|
|
|
203 |
# Sample the frames every 5 seconds
|
204 |
if time.time() - start_time >= LENGTH:
|
205 |
# Start a new thread for processing the video clip
|
206 |
+
Thread(target=process_clip, args=(prompt, frames.copy(), chatbot, id)).start()
|
207 |
frames = []
|
208 |
start_time = time.time()
|
209 |
+
id+=1
|
210 |
yield chatbot
|
211 |
|
212 |
cap.release()
|