File size: 1,925 Bytes
76a8957
 
e8d1963
d347385
9d315b3
d347385
 
 
e8d1963
 
 
 
d347385
 
e8d1963
d347385
 
7e4124b
 
 
9ac40ae
 
7e4124b
 
 
 
 
 
9d315b3
 
d347385
 
 
aabba29
 
d347385
 
 
4c10a90
76a8957
 
 
d347385
 
 
 
e8d1963
d347385
76a8957
 
d347385
76a8957
4c10a90
76a8957
4c10a90
9d315b3
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
import gradio as gr
from textblob import TextBlob
from utils import *
import tempfile
from get_transcripts_with_openai import get_langchain_Document_for_rag

def answer_video_question(query : str, url : str, file : bytes) -> dict:
    # Either `file` or `url` must be provided

    output_path='/tmp/video'
    if not os.path.exists(output_path):
        os.mkdir(output_path)
    if file is not None:
        with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_vid:
            temp_vid.write(file)
            temp_video_path = temp_vid.name



        # Output frames Documents()
        all_frames_data = extract_nfps_frames(temp_video_path)
        langchain_documents = provide_video_RAG(all_frames_data)


        langchain_transcripts = get_langchain_Document_for_rag(temp_video_path)


        os.unlink(temp_video_path) # clean up extracted file
        return {"status_vid_frame_from_file":all_frames_data,
        "langchain transcript":str(langchain_transcripts)}

    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)",type='binary')
    ],
    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, server_port=7777)