Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,14 +94,13 @@ class ShopliftingPrediction:
|
|
| 94 |
probability = math.floor(max(probabilities[0], probabilities[1]) * 100)
|
| 95 |
return [probability, predicted_label]
|
| 96 |
|
| 97 |
-
def Process_Stream(self, stream_url, output_file_path=None,
|
| 98 |
"""
|
| 99 |
Process a live video stream for shoplifting detection
|
| 100 |
|
| 101 |
Args:
|
| 102 |
stream_url: URL to the HTTP live stream or path to local video file
|
| 103 |
output_file_path: Where to save the processed video (if None, a temp file is created)
|
| 104 |
-
max_duration: Maximum duration to process in seconds (for streams)
|
| 105 |
buffer_size: Size of frames to buffer before processing (if None, use sequence_length)
|
| 106 |
|
| 107 |
Returns:
|
|
@@ -149,11 +148,6 @@ class ShopliftingPrediction:
|
|
| 149 |
frame_count = 0
|
| 150 |
|
| 151 |
while self.video_reader.isOpened():
|
| 152 |
-
# Check if we've exceeded the max duration for streams
|
| 153 |
-
if is_url and (time.time() - start_time) > max_duration:
|
| 154 |
-
logging.info(f"Reached maximum stream capture duration of {max_duration} seconds")
|
| 155 |
-
break
|
| 156 |
-
|
| 157 |
# Read the next frame
|
| 158 |
ok, frame = self.video_reader.read()
|
| 159 |
if not ok:
|
|
@@ -210,13 +204,12 @@ class ShopliftingPrediction:
|
|
| 210 |
def inference(model_path):
|
| 211 |
shoplifting_prediction = ShopliftingPrediction(model_path, 90, 90, sequence_length=160)
|
| 212 |
|
| 213 |
-
def process_input(input_source
|
| 214 |
"""
|
| 215 |
Process either a video file upload or a streaming URL
|
| 216 |
|
| 217 |
Args:
|
| 218 |
input_source: Either a URL string or a path to an uploaded video file
|
| 219 |
-
max_duration: Maximum duration to process for streams (in seconds)
|
| 220 |
|
| 221 |
Returns:
|
| 222 |
Path to the processed video file
|
|
@@ -227,7 +220,7 @@ def inference(model_path):
|
|
| 227 |
if isinstance(input_source, str):
|
| 228 |
# Input is likely a URL
|
| 229 |
logging.info(f"Processing input as URL: {input_source}")
|
| 230 |
-
return shoplifting_prediction.Process_Stream(input_source, output_file_path
|
| 231 |
else:
|
| 232 |
# Input is likely an uploaded file
|
| 233 |
logging.info(f"Processing input as uploaded file: {input_source}")
|
|
@@ -258,18 +251,11 @@ with gr.Blocks(title="Shoplifting Detection System") as iface:
|
|
| 258 |
label="Enter HTTP Live Stream URL",
|
| 259 |
placeholder="https://example.com/stream.m3u8"
|
| 260 |
)
|
| 261 |
-
max_duration = gr.Slider(
|
| 262 |
-
minimum=5,
|
| 263 |
-
maximum=120,
|
| 264 |
-
value=30,
|
| 265 |
-
step=5,
|
| 266 |
-
label="Max Stream Duration (seconds)"
|
| 267 |
-
)
|
| 268 |
stream_submit = gr.Button("Process Stream")
|
| 269 |
stream_output = gr.Video()
|
| 270 |
stream_submit.click(
|
| 271 |
fn=process_input,
|
| 272 |
-
inputs=[stream_url
|
| 273 |
outputs=stream_output
|
| 274 |
)
|
| 275 |
|
|
|
|
| 94 |
probability = math.floor(max(probabilities[0], probabilities[1]) * 100)
|
| 95 |
return [probability, predicted_label]
|
| 96 |
|
| 97 |
+
def Process_Stream(self, stream_url, output_file_path=None, buffer_size=None):
|
| 98 |
"""
|
| 99 |
Process a live video stream for shoplifting detection
|
| 100 |
|
| 101 |
Args:
|
| 102 |
stream_url: URL to the HTTP live stream or path to local video file
|
| 103 |
output_file_path: Where to save the processed video (if None, a temp file is created)
|
|
|
|
| 104 |
buffer_size: Size of frames to buffer before processing (if None, use sequence_length)
|
| 105 |
|
| 106 |
Returns:
|
|
|
|
| 148 |
frame_count = 0
|
| 149 |
|
| 150 |
while self.video_reader.isOpened():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
# Read the next frame
|
| 152 |
ok, frame = self.video_reader.read()
|
| 153 |
if not ok:
|
|
|
|
| 204 |
def inference(model_path):
|
| 205 |
shoplifting_prediction = ShopliftingPrediction(model_path, 90, 90, sequence_length=160)
|
| 206 |
|
| 207 |
+
def process_input(input_source):
|
| 208 |
"""
|
| 209 |
Process either a video file upload or a streaming URL
|
| 210 |
|
| 211 |
Args:
|
| 212 |
input_source: Either a URL string or a path to an uploaded video file
|
|
|
|
| 213 |
|
| 214 |
Returns:
|
| 215 |
Path to the processed video file
|
|
|
|
| 220 |
if isinstance(input_source, str):
|
| 221 |
# Input is likely a URL
|
| 222 |
logging.info(f"Processing input as URL: {input_source}")
|
| 223 |
+
return shoplifting_prediction.Process_Stream(input_source, output_file_path)
|
| 224 |
else:
|
| 225 |
# Input is likely an uploaded file
|
| 226 |
logging.info(f"Processing input as uploaded file: {input_source}")
|
|
|
|
| 251 |
label="Enter HTTP Live Stream URL",
|
| 252 |
placeholder="https://example.com/stream.m3u8"
|
| 253 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
stream_submit = gr.Button("Process Stream")
|
| 255 |
stream_output = gr.Video()
|
| 256 |
stream_submit.click(
|
| 257 |
fn=process_input,
|
| 258 |
+
inputs=[stream_url],
|
| 259 |
outputs=stream_output
|
| 260 |
)
|
| 261 |
|