nagasurendra commited on
Commit
223eefb
·
verified ·
1 Parent(s): a6ac107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -55
app.py CHANGED
@@ -1,62 +1,67 @@
1
- import streamlit as st
2
- from utils.video_processor import compare_videos
3
  import os
 
4
 
5
- # Set page configuration
6
- st.set_page_config(page_title="Video Comparison App", layout="wide")
7
-
8
- # Title and description
9
- st.title("Video Comparison App")
10
- st.write("Upload two videos of the same duration to compare frame-by-frame differences.")
11
-
12
- # File uploaders
13
- col1, col2 = st.columns(2)
14
- with col1:
15
- video1_file = st.file_uploader("Upload First Video", type=["mp4", "avi", "mov"])
16
- with col2:
17
- video2_file = st.file_uploader("Upload Second Video", type=["mp4", "avi", "mov"])
18
-
19
- # Submit button
20
- if st.button("Compare Videos"):
21
- if video1_file is None or video2_file is None:
22
- st.error("Please upload both videos.")
23
- else:
24
- # Save uploaded videos temporarily
25
- os.makedirs("temp", exist_ok=True)
26
- video1_path = os.path.join("temp", video1_file.name)
27
- video2_path = os.path.join("temp", video2_file.name)
28
-
29
- with open(video1_path, "wb") as f:
30
- f.write(video1_file.getbuffer())
31
- with open(video2_path, "wb") as f:
32
- f.write(video2_file.getbuffer())
33
 
34
- try:
35
- # Compare videos
36
- plot_path, diff_video_path = compare_videos(video1_path, video2_path)
37
-
38
- # Display results
39
- st.success("Comparison complete!")
40
- st.subheader("Difference Plot")
41
- st.image(plot_path, caption="Frame-by-frame SSIM Difference (%)")
42
-
43
- st.subheader("Difference Video")
44
- with open(diff_video_path, "rb") as f:
45
- st.video(f.read())
46
-
47
- # Clean up temporary files
48
  os.remove(video1_path)
 
49
  os.remove(video2_path)
50
- os.remove(plot_path)
51
- os.remove(diff_video_path)
52
-
53
- except Exception as e:
54
- st.error(f"Error during comparison: {str(e)}")
55
- # Clean up temporary files if they exist
56
- if os.path.exists(video1_path):
57
- os.remove(video1_path)
58
- if os.path.exists(video2_path):
59
- os.remove(video2_path)
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  if __name__ == "__main__":
62
- os.makedirs("utils/output", exist_ok=True)
 
 
1
+ import gradio as gr
 
2
  import os
3
+ from utils.video_processor import compare_videos
4
 
5
+ def compare_videos_interface(video1, video2):
6
+ if video1 is None or video2 is None:
7
+ return "Please upload both videos.", None, None
8
+
9
+ # Save uploaded videos temporarily
10
+ os.makedirs("temp", exist_ok=True)
11
+ video1_path = os.path.join("temp", os.path.basename(video1))
12
+ video2_path = os.path.join("temp", os.path.basename(video2))
13
+
14
+ # Copy uploaded files to temp directory
15
+ with open(video1_path, "wb") as f:
16
+ with open(video1, "rb") as v1:
17
+ f.write(v1.read())
18
+ with open(video2_path, "wb") as f:
19
+ with open(video2, "rb") as v2:
20
+ f.write(v2.read())
21
+
22
+ try:
23
+ # Compare videos
24
+ plot_path, diff_video_path = compare_videos(video1_path, video2_path)
 
 
 
 
 
 
 
 
25
 
26
+ # Return results
27
+ return (
28
+ "Comparison complete!",
29
+ plot_path,
30
+ diff_video_path
31
+ )
32
+
33
+ except Exception as e:
34
+ return f"Error during comparison: {str(e)}", None, None
35
+
36
+ finally:
37
+ # Clean up temporary files
38
+ if os.path.exists(video1_path):
 
39
  os.remove(video1_path)
40
+ if os.path.exists(video2_path):
41
  os.remove(video2_path)
 
 
 
 
 
 
 
 
 
 
42
 
43
+ # Define Gradio interface
44
+ with gr.Blocks(title="Video Comparison App") as demo:
45
+ gr.Markdown("# Video Comparison App")
46
+ gr.Markdown("Upload two videos of the same duration to compare frame-by-frame differences.")
47
+
48
+ with gr.Row():
49
+ video1_input = gr.Video(label="Upload First Video", format=["mp4", "avi", "mov"])
50
+ video2_input = gr.Video(label="Upload Second Video", format=["mp4", "avi", "mov"])
51
+
52
+ submit_button = gr.Button("Compare Videos")
53
+
54
+ output_text = gr.Textbox(label="Status")
55
+ output_plot = gr.Image(label="Difference Plot")
56
+ output_video = gr.Video(label="Difference Video")
57
+
58
+ submit_button.click(
59
+ fn=compare_videos_interface,
60
+ inputs=[video1_input, video2_input],
61
+ outputs=[output_text, output_plot, output_video]
62
+ )
63
+
64
+ # Launch the app
65
  if __name__ == "__main__":
66
+ os.makedirs("utils/output", exist_ok=True)
67
+ demo.launch()