Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,26 @@ client = openai.OpenAI(api_key=api_key)
|
|
| 41 |
stop_capture = False
|
| 42 |
alerts_mode = True
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
def encode_to_video(frames, fps):
|
| 46 |
os.makedirs('videos', exist_ok=True)
|
|
@@ -115,7 +135,7 @@ def process_clip(prompt, frames, chatbot):
|
|
| 115 |
|
| 116 |
if api_response["condition_met"] == True:
|
| 117 |
finish_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
| 118 |
-
video_clip_path =
|
| 119 |
chatbot.append(((video_clip_path,), None))
|
| 120 |
result = f"Time: {start_time}\n"
|
| 121 |
chatbot.append((result, None))
|
|
@@ -142,7 +162,7 @@ def process_clip_from_file(prompt, frames, chatbot, fps):
|
|
| 142 |
|
| 143 |
result = None
|
| 144 |
if api_response and api_response.get("condition_met", False):
|
| 145 |
-
video_clip_path =
|
| 146 |
chatbot.append(((video_clip_path,), None))
|
| 147 |
chatbot.append((f"Time: {start_time}\nDetails: {api_response.get('details', '')}", None))
|
| 148 |
|
|
|
|
| 41 |
stop_capture = False
|
| 42 |
alerts_mode = True
|
| 43 |
|
| 44 |
+
def encode_to_video_fast(frames, fps):
|
| 45 |
+
|
| 46 |
+
os.makedirs('videos', exist_ok=True)
|
| 47 |
+
video_clip_path = f"videos/{uuid.uuid4()}.mp4"
|
| 48 |
+
|
| 49 |
+
# Get frame size
|
| 50 |
+
height, width, layers = frames[0].shape
|
| 51 |
+
size = (width, height)
|
| 52 |
+
|
| 53 |
+
# Define the codec and create VideoWriter object
|
| 54 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # You can also try 'XVID', 'MJPG', etc.
|
| 55 |
+
out = cv2.VideoWriter(video_clip_path, fourcc, fps, size)
|
| 56 |
+
|
| 57 |
+
for frame in frames:
|
| 58 |
+
out.write(frame)
|
| 59 |
+
|
| 60 |
+
out.release()
|
| 61 |
+
|
| 62 |
+
return video_clip_path
|
| 63 |
+
|
| 64 |
|
| 65 |
def encode_to_video(frames, fps):
|
| 66 |
os.makedirs('videos', exist_ok=True)
|
|
|
|
| 135 |
|
| 136 |
if api_response["condition_met"] == True:
|
| 137 |
finish_time = datetime.now(israel_tz).strftime('%H:%M:%S')
|
| 138 |
+
video_clip_path = encode_to_video_fast(frames, fps)
|
| 139 |
chatbot.append(((video_clip_path,), None))
|
| 140 |
result = f"Time: {start_time}\n"
|
| 141 |
chatbot.append((result, None))
|
|
|
|
| 162 |
|
| 163 |
result = None
|
| 164 |
if api_response and api_response.get("condition_met", False):
|
| 165 |
+
video_clip_path = encode_to_video_fast(frames, fps)
|
| 166 |
chatbot.append(((video_clip_path,), None))
|
| 167 |
chatbot.append((f"Time: {start_time}\nDetails: {api_response.get('details', '')}", None))
|
| 168 |
|