Spaces:
Running
Running
Handling the edge cases
Browse files
app.py
CHANGED
@@ -192,6 +192,18 @@ def predict_video(model, video_path):
|
|
192 |
return original_frames, predicted_label, probability
|
193 |
|
194 |
def display_frames_and_prediction(video_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
|
196 |
temp_file_path = temp_file.name
|
197 |
|
@@ -216,7 +228,7 @@ def display_frames_and_prediction(video_file):
|
|
216 |
|
217 |
iface = gr.Interface(
|
218 |
fn=display_frames_and_prediction,
|
219 |
-
inputs=gr.File(label="Upload Video"),
|
220 |
outputs=[
|
221 |
gr.Gallery(label="Extracted Frames"),
|
222 |
gr.HTML(label="Prediction"),
|
|
|
192 |
return original_frames, predicted_label, probability
|
193 |
|
194 |
def display_frames_and_prediction(video_file):
|
195 |
+
# Ensure file is completely uploaded and of correct type
|
196 |
+
if video_file is None:
|
197 |
+
return [], "<div style='color: red;'>No video uploaded!</div>", ""
|
198 |
+
|
199 |
+
# Check file size (10 MB limit)
|
200 |
+
if os.path.getsize(video_file) > 10 * 1024 * 1024: # 10 MB
|
201 |
+
return [], "<div style='color: red;'>File size exceeds 10 MB limit!</div>", ""
|
202 |
+
|
203 |
+
# Check file extension
|
204 |
+
if not video_file.endswith('.mp4'):
|
205 |
+
return [], "<div style='color: red;'>Only .mp4 files are allowed!</div>", ""
|
206 |
+
|
207 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
|
208 |
temp_file_path = temp_file.name
|
209 |
|
|
|
228 |
|
229 |
iface = gr.Interface(
|
230 |
fn=display_frames_and_prediction,
|
231 |
+
inputs=gr.File(label="Upload Video", interactive=True),
|
232 |
outputs=[
|
233 |
gr.Gallery(label="Extracted Frames"),
|
234 |
gr.HTML(label="Prediction"),
|