TAneKAnz commited on
Commit
bb90a83
·
verified ·
1 Parent(s): 6b0401b

history_log

Browse files
Files changed (1) hide show
  1. app.py +41 -22
app.py CHANGED
@@ -1,15 +1,22 @@
1
  import cv2
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"
10
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
11
  height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
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
 
@@ -24,28 +31,40 @@ def convert_to_grayscale(video_file):
24
  cap.release()
25
  out.release()
26
 
27
- return output_file
 
 
 
 
 
 
 
28
 
29
- # function to get history (coming soon)
30
- def get_history():
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",
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()
 
1
  import cv2
2
  import gradio as gr
3
  import os
4
+ from datetime import datetime
5
+ import time
6
+ import psutil
7
 
8
+ def convert_to_grayscale(video_file, history):
9
+ start_time = time.time()
10
+ file_name = os.path.splitext(os.path.basename(video_file))[0]
11
+ output_file = f"{file_name}_output.mp4"
12
 
 
13
  cap = cv2.VideoCapture(video_file)
 
14
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
15
  height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
16
  fps = int(cap.get(cv2.CAP_PROP_FPS))
17
+ frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
18
+ video_duration = frame_count / fps
19
+
20
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
21
  out = cv2.VideoWriter(output_file, fourcc, fps, (width, height), isColor=False)
22
 
 
31
  cap.release()
32
  out.release()
33
 
34
+ end_time = time.time()
35
+ process_time = end_time - start_time
36
+ current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
37
+ memory_usage = psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 # in MB
38
+
39
+ history.append(f"#{len(history)+1} File Name: {file_name}, Collected on: {current_time}, Video Duration: {video_duration:.2f} seconds, Processing Time: {process_time:.2f} seconds, Memory Usage: {memory_usage:.2f} MB")
40
+
41
+ return output_file, history
42
 
43
+ def get_history(history):
44
+ history_html = "<br>".join(history)
 
45
  return history_html
46
 
47
+ with gr.Blocks() as demo:
48
+ history_state = gr.State([])
49
+
50
+ with gr.Tab("Convert Video"):
51
+ with gr.Row(""):
52
+ video_input = gr.Video(label="Upload Video", height=500, width=500)
53
+ video_output = gr.Video(label="Grayscale Video", height=500, width=500)
54
+ convert_button = gr.Button("Convert")
55
+
56
+ convert_button.click(
57
+ fn=convert_to_grayscale,
58
+ inputs=[video_input, history_state],
59
+ outputs=[video_output, history_state]
60
+ )
61
+
62
+ with gr.Tab("History") as history_tab:
63
+ history_output = gr.HTML(label="History")
64
 
65
+ def update_history(history):
66
+ return get_history(history)
 
 
 
 
 
67
 
68
+ convert_button.click(fn=update_history, inputs=history_state, outputs=history_output)
 
 
 
 
 
 
69
 
70
+ demo.launch()