Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,30 +17,33 @@ def process_frame(frame):
|
|
| 17 |
return prediction[0][1] # Assuming category 1 is jumpscare
|
| 18 |
|
| 19 |
def convert_video_to_dumpscare(video_path, sensitivity):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Gradio interface function
|
| 41 |
def gradio_interface(video, sensitivity):
|
| 42 |
-
|
| 43 |
-
return output_video
|
| 44 |
|
| 45 |
# Set up Gradio app
|
| 46 |
iface = gr.Interface(
|
|
|
|
| 17 |
return prediction[0][1] # Assuming category 1 is jumpscare
|
| 18 |
|
| 19 |
def convert_video_to_dumpscare(video_path, sensitivity):
|
| 20 |
+
try:
|
| 21 |
+
cap = cv2.VideoCapture(video_path)
|
| 22 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 23 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 24 |
+
|
| 25 |
+
output_path = 'output_dumpscare.mp4'
|
| 26 |
+
out = cv2.VideoWriter(output_path, fourcc, fps, (int(cap.get(3)), int(cap.get(4))))
|
| 27 |
+
|
| 28 |
+
while cap.isOpened():
|
| 29 |
+
ret, frame = cap.read()
|
| 30 |
+
if not ret:
|
| 31 |
+
break
|
| 32 |
+
|
| 33 |
+
# Check if the frame is a jumpscare
|
| 34 |
+
if process_frame(frame) > sensitivity: # Use sensitivity slider
|
| 35 |
+
out.write(frame) # Write frame if it's a jumpscare
|
| 36 |
+
|
| 37 |
+
cap.release()
|
| 38 |
+
out.release()
|
| 39 |
+
return output_path
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error processing video: {str(e)}"
|
| 43 |
|
| 44 |
# Gradio interface function
|
| 45 |
def gradio_interface(video, sensitivity):
|
| 46 |
+
return convert_video_to_dumpscare(video.name, sensitivity)
|
|
|
|
| 47 |
|
| 48 |
# Set up Gradio app
|
| 49 |
iface = gr.Interface(
|