Spaces:
Runtime error
Runtime error
grey-scale
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import cv2
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
|
|
|
|
5 |
def convert_to_grayscale(video_file):
|
6 |
cap = cv2.VideoCapture(video_file)
|
7 |
output_file = "output.mp4"
|
@@ -10,24 +12,40 @@ def convert_to_grayscale(video_file):
|
|
10 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
11 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
12 |
out = cv2.VideoWriter(output_file, fourcc, fps, (width, height), isColor=False)
|
13 |
-
|
14 |
while(cap.isOpened()):
|
15 |
ret, frame = cap.read()
|
16 |
if not ret:
|
17 |
break
|
18 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
19 |
-
|
20 |
-
|
|
|
21 |
cap.release()
|
22 |
out.release()
|
23 |
-
|
24 |
return output_file
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
demo = gr.Interface(
|
27 |
fn=convert_to_grayscale,
|
28 |
title="Video Upload and Display",
|
29 |
inputs=gr.Video(label="Upload Video", height=500, width=500),
|
30 |
outputs=gr.Video(label="Grayscale Video", height=500, width=500),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
|
33 |
-
demo.launch()
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
5 |
+
video_history = []
|
6 |
+
|
7 |
def convert_to_grayscale(video_file):
|
8 |
cap = cv2.VideoCapture(video_file)
|
9 |
output_file = "output.mp4"
|
|
|
12 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
13 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
14 |
out = cv2.VideoWriter(output_file, fourcc, fps, (width, height), isColor=False)
|
15 |
+
|
16 |
while(cap.isOpened()):
|
17 |
ret, frame = cap.read()
|
18 |
if not ret:
|
19 |
break
|
20 |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
21 |
+
gray_flipped = cv2.flip(gray, 1)
|
22 |
+
out.write(gray_flipped)
|
23 |
+
|
24 |
cap.release()
|
25 |
out.release()
|
26 |
+
|
27 |
return output_file
|
28 |
|
29 |
+
def get_history():
|
30 |
+
# Create HTML links to the flagged videos
|
31 |
+
history_html = ""
|
32 |
+
return history_html
|
33 |
+
|
34 |
+
|
35 |
demo = gr.Interface(
|
36 |
fn=convert_to_grayscale,
|
37 |
title="Video Upload and Display",
|
38 |
inputs=gr.Video(label="Upload Video", height=500, width=500),
|
39 |
outputs=gr.Video(label="Grayscale Video", height=500, width=500),
|
40 |
+
allow_flagging="manual", # Enable flag button
|
41 |
+
)
|
42 |
+
|
43 |
+
history_demo = gr.Interface(
|
44 |
+
fn=get_history,
|
45 |
+
title="Processed Video History",
|
46 |
+
inputs=[],
|
47 |
+
outputs=gr.Textbox(label="History"),
|
48 |
+
allow_flagging="never"
|
49 |
)
|
50 |
|
51 |
+
gr.TabbedInterface([demo, history_demo], ["Convert Video", "History"]).launch()
|