Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,9 +19,17 @@ def process_frame(frame):
|
|
19 |
def convert_video_to_dumpscare(video, sensitivity):
|
20 |
# Initialize the output
|
21 |
output_frames = []
|
22 |
-
|
23 |
# Read the video
|
24 |
cap = cv2.VideoCapture(video)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
while cap.isOpened():
|
26 |
ret, frame = cap.read()
|
27 |
if not ret:
|
@@ -29,10 +37,17 @@ def convert_video_to_dumpscare(video, sensitivity):
|
|
29 |
|
30 |
# Process each frame
|
31 |
prediction = process_frame(frame)
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
cap.release()
|
35 |
-
|
|
|
|
|
36 |
|
37 |
def gradio_interface(video, sensitivity):
|
38 |
result = convert_video_to_dumpscare(video, sensitivity)
|
@@ -42,10 +57,10 @@ def gradio_interface(video, sensitivity):
|
|
42 |
iface = gr.Interface(
|
43 |
fn=gradio_interface,
|
44 |
inputs=[
|
45 |
-
gr.Video(label="Import Video"),
|
46 |
-
gr.Slider(label="Sensitivity", minimum=0, maximum=100, step=1, value=50)
|
47 |
],
|
48 |
-
outputs="
|
49 |
)
|
50 |
|
51 |
# Launch the app
|
|
|
19 |
def convert_video_to_dumpscare(video, sensitivity):
|
20 |
# Initialize the output
|
21 |
output_frames = []
|
22 |
+
|
23 |
# Read the video
|
24 |
cap = cv2.VideoCapture(video)
|
25 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
26 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
27 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
28 |
+
|
29 |
+
# Define the codec and create a VideoWriter object
|
30 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
31 |
+
out = cv2.VideoWriter('output_dumpscare.mp4', fourcc, fps, (width, height))
|
32 |
+
|
33 |
while cap.isOpened():
|
34 |
ret, frame = cap.read()
|
35 |
if not ret:
|
|
|
37 |
|
38 |
# Process each frame
|
39 |
prediction = process_frame(frame)
|
40 |
+
|
41 |
+
# Here you can modify the frame based on prediction if needed
|
42 |
+
output_frames.append(frame) # For now, just appending the original frame
|
43 |
+
|
44 |
+
# Write the frame to the output video
|
45 |
+
out.write(frame)
|
46 |
|
47 |
cap.release()
|
48 |
+
out.release()
|
49 |
+
|
50 |
+
return 'output_dumpscare.mp4' # Return the path to the saved video
|
51 |
|
52 |
def gradio_interface(video, sensitivity):
|
53 |
result = convert_video_to_dumpscare(video, sensitivity)
|
|
|
57 |
iface = gr.Interface(
|
58 |
fn=gradio_interface,
|
59 |
inputs=[
|
60 |
+
gr.Video(label="Import Video"),
|
61 |
+
gr.Slider(label="Sensitivity", minimum=0, maximum=100, step=1, value=50)
|
62 |
],
|
63 |
+
outputs=gr.File(label="Output Video") # Output will be a video file
|
64 |
)
|
65 |
|
66 |
# Launch the app
|