|
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: |
|
|
|
yt = YouTube(video_url) |
|
|
|
|
|
video_stream = yt.streams.get_highest_resolution() |
|
|
|
|
|
file_path = video_stream.download(DATA_DIR) |
|
return file_path |
|
except Exception as e: |
|
return None |
|
|
|
|
|
def main(): |
|
try: |
|
st.title("VideoClarify") |
|
|
|
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) |
|
|
|
transcript = get_cached_transcript(video_url) |
|
|
|
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.") |
|
|
|
response = gemini(transcript, question) |
|
if selected_model == "OpenAI": |
|
st.info("Using OpenAI to answer the question.") |
|
|
|
response = get_completion(transcript, question) |
|
|
|
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() |
|
|