File size: 2,408 Bytes
223eefb
d3d41bd
65964c5
223eefb
d3d41bd
223eefb
 
 
 
0b68c85
 
65964c5
 
0b68c85
 
223eefb
 
65964c5
 
223eefb
 
65964c5
 
223eefb
 
 
 
d3d41bd
223eefb
 
 
 
 
 
 
 
 
 
 
 
 
1a4fcc5
223eefb
1a4fcc5
 
223eefb
 
 
0b68c85
223eefb
 
0b68c85
 
223eefb
 
 
 
 
 
 
 
 
 
 
 
 
 
1a4fcc5
223eefb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import os
import shutil
from utils.video_processor import compare_videos

def compare_videos_interface(video1, video2):
    if video1 is None or video2 is None:
        return "Please upload both videos.", None, None
    
    # Validate file extensions
    valid_extensions = [".mp4", ".avi", ".mov"]
    if not any(video1.lower().endswith(ext) for ext in valid_extensions) or \
       not any(video2.lower().endswith(ext) for ext in valid_extensions):
        return "Invalid video format. Please upload MP4, AVI, or MOV files.", None, None
    
    # Save uploaded videos temporarily
    os.makedirs("temp", exist_ok=True)
    video1_path = os.path.join("temp", os.path.basename(video1))
    video2_path = os.path.join("temp", os.path.basename(video2))
    
    # Copy uploaded files to temp directory
    shutil.copy(video1, video1_path)
    shutil.copy(video2, video2_path)
    
    try:
        # Compare videos
        plot_path, diff_video_path = compare_videos(video1_path, video2_path)
        
        # Return results
        return (
            "Comparison complete!",
            plot_path,
            diff_video_path
        )
    
    except Exception as e:
        return f"Error during comparison: {str(e)}", None, None
    
    finally:
        # Clean up temporary files
        if os.path.exists(video1_path):
            os.remove(video1_path)
        if os.path.exists(video2_path):
            os.remove(video2_path)

# Define Gradio interface
with gr.Blocks(title="Video Comparison App") as demo:
    gr.Markdown("# Video Comparison App")
    gr.Markdown("Upload two videos of the same duration (MP4, AVI, MOV) to compare frame-by-frame differences.")
    
    with gr.Row():
        video1_input = gr.File(label="Upload First Video", file_types=[".mp4", ".avi", ".mov"])
        video2_input = gr.File(label="Upload Second Video", file_types=[".mp4", ".avi", ".mov"])
    
    submit_button = gr.Button("Compare Videos")
    
    output_text = gr.Textbox(label="Status")
    output_plot = gr.Image(label="Difference Plot")
    output_video = gr.Video(label="Difference Video")
    
    submit_button.click(
        fn=compare_videos_interface,
        inputs=[video1_input, video2_input],
        outputs=[output_text, output_plot, output_video]
    )

# Launch the app
if __name__ == "__main__":
    os.makedirs("utils/output", exist_ok=True)
    demo.launch()