File size: 1,425 Bytes
76a8957
 
d347385
 
 
 
 
 
 
 
 
 
 
 
aabba29
d347385
aabba29
d347385
 
 
aabba29
 
d347385
 
 
4c10a90
76a8957
 
 
d347385
 
 
 
 
 
76a8957
 
d347385
76a8957
4c10a90
76a8957
4c10a90
76a8957
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
import gradio as gr
from textblob import TextBlob
import utils
import tempfile


def answer_video_question(query : str, url : str, file : bytes) -> dict:
    # Either `file` or `url` must be provided
    if file is not None:
        with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_vid:
            temp_vid.write(file.read())
            temp_video_path = temp_vid.name

        # Output frame folder
        check = extract_keyframes(temp_video_path)

        return {"status_vid_frame_from_file":check}

    elif url:
        files_path = download_video(url)
        check = extract_keyframes(files_path['video_path'])
        return {"out_vid_path_from_url":check}

    else:
        return {"error": "Please provide a movie file or URL."}


# Create the Gradio interface
demo = gr.Interface(
    fn=answer_video_question,
    inputs=[
        gr.Textbox(placeholder="Enter Query about the movie", label="Query"),
        gr.Textbox(placeholder="Paste the URL of the movie", label="Movie URL (optional)"),
        gr.File(label="Upload Movie File (optional)")
    ],
    outputs=gr.JSON(),
    title="Text Sentiment Analysis",
    description="Ask a question about a movie. You can provide a movie via a URL or by uploading a file. The movie will be cached and deleted when the Space goes to sleep."
)

# Launch the interface and MCP server
if __name__ == "__main__":
    demo.launch(mcp_server=True)