File size: 2,886 Bytes
0ad7e2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64a70c0
0ad7e2a
 
 
 
 
 
64a70c0
0ad7e2a
 
64a70c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
"""
Split tab for Video Model Studio UI
"""

import gradio as gr
import logging
from typing import Dict, Any, List, Optional

from .base_tab import BaseTab

logger = logging.getLogger(__name__)

class SplitTab(BaseTab):
    """Split tab for scene detection and video splitting"""
    
    def __init__(self, app_state):
        super().__init__(app_state)
        self.id = "split_tab"
        self.title = "2️⃣  Split"
    
    def create(self, parent=None) -> gr.TabItem:
        """Create the Split tab UI components"""
        with gr.TabItem(self.title, id=self.id) as tab:
            with gr.Row():
                self.components["split_title"] = gr.Markdown("## Splitting of 0 videos (0 bytes)")
            
            with gr.Row():
                with gr.Column():
                    self.components["detect_btn"] = gr.Button("Split videos into single-camera shots", variant="primary")
                    self.components["detect_status"] = gr.Textbox(label="Status", interactive=False)

                with gr.Column():
                    self.components["video_list"] = gr.Dataframe(
                        headers=["name", "status"],
                        label="Videos to split",
                        interactive=False,
                        wrap=True
                    )
                    
        return tab
    
    def connect_events(self) -> None:
        """Connect event handlers to UI components"""
        # Scene detection button event
        self.components["detect_btn"].click(
            fn=self.start_scene_detection,
            inputs=[self.app.tabs["import_tab"].components["enable_automatic_video_split"]],
            outputs=[self.components["detect_status"]]
        )
        
    def refresh(self) -> Dict[str, Any]:
        """Refresh the video list with current data"""
        videos = self.list_unprocessed_videos()
        return {
            "video_list": videos
        }
    
    def list_unprocessed_videos(self) -> gr.Dataframe:
        """Update list of unprocessed videos"""
        videos = self.app.splitter.list_unprocessed_videos()
        # videos is already in [[name, status]] format from splitting_service
        return gr.Dataframe(
            headers=["name", "status"],
            value=videos,
            interactive=False
        )

    async def start_scene_detection(self, enable_splitting: bool) -> str:
        """Start background scene detection process
        
        Args:
            enable_splitting: Whether to split videos into scenes
        """
        if self.app.splitter.is_processing():
            return "Scene detection already running"
            
        try:
            await self.app.splitter.start_processing(enable_splitting)
            return "Scene detection completed"
        except Exception as e:
            return f"Error during scene detection: {str(e)}"