File size: 3,054 Bytes
8677234
38efda5
 
8677234
 
 
 
 
 
 
 
 
 
38efda5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8677234
690a126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8677234
690a126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8677234
 
 
 
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
import streamlit as st
from pytube import YouTube
from settings import DATA_DIR
from lib.services.hf_model import get_transcript
from lib.services.gemini import gemini
from lib.services.openai import get_completion


@st.cache_resource
def get_cached_transcript(video_url):
    return get_transcript(video_url)


def download_youtube_video(video_url):
    try:
        # Create a YouTube object
        yt = YouTube(video_url)

        # Get the highest resolution stream
        video_stream = yt.streams.get_highest_resolution()

        # Download the video to the specified output path
        file_path = video_stream.download(DATA_DIR)
        return file_path
    except Exception as e:
        return None


def main():
    try:
        st.title("VideoClarify")
        # Get video URL from user
        video_url = st.text_input("Enter YouTube URL:", key="video_url")
        selected_model = st.sidebar.selectbox("Select Model", ["Gemini", "OpenAI"])
        st.sidebar.subheader("About Tool:")
        st.sidebar.markdown("""
                            VideoClarify is a tool that uses AI to summarize and answer questions about a video.
                            """)
        st.sidebar.subheader("Explore These Questions:")
        st.sidebar.markdown("""
        1. Can you summarize the key points or message of the video?
        2. What is the central theme or main idea conveyed in the video? 
        3. What specific examples or evidence are provided in the video to support the main points?
        4. Is there a specific term or jargon used in the video that I need to clarify?
        5. Write a well structure article based on this video
        """)

        if len(video_url):
            video_url = download_youtube_video(video_url)
            print(video_url)
            st.video(video_url)
            # Get transcript from the video
            transcript = get_cached_transcript(video_url)
            # Provide an input box for user to ask a question
            question = st.text_input(
                label="Ask a question about the video:", key="question")

            if st.button("Get Answer"):
                if question:
                    if selected_model == "Gemini":
                        st.info("Using Gemini to answer the question.")
                        # Use Gemini to summarize and answer the question
                        response = gemini(transcript, question)
                    if selected_model == "OpenAI":
                        st.info("Using OpenAI to answer the question.")
                        # Use OpenAI to summarize and answer the question
                        response = get_completion(transcript, question)
                    # Display the result to the user
                    st.subheader("Result:")
                    st.write(response)
                else:
                    st.info("Please ask a question about the video.")
    except Exception as e:
        st.write("Please refresh the page and try again.")


if __name__ == "__main__":
    main()