|
import streamlit as st
|
|
from youtube_subtitle_generator import extract_video_id, get_available_languages, get_subtitles
|
|
from llm_response import llm_generator
|
|
from fpdf import FPDF
|
|
import time
|
|
|
|
|
|
st.sidebar.title("π API Key Setup")
|
|
nvidia_api_key = st.sidebar.text_input("Enter your NVIDIA API Key:", type="password")
|
|
|
|
if not nvidia_api_key:
|
|
st.sidebar.warning("Please enter your NVIDIA API Key to proceed.")
|
|
else:
|
|
|
|
st.title("πΊ YouTube to Study Notes")
|
|
|
|
|
|
video_url = st.text_input("π₯ Enter YouTube Video URL:")
|
|
|
|
if video_url:
|
|
video_id = extract_video_id(video_url)
|
|
|
|
if video_id:
|
|
available_languages = get_available_languages(video_id)
|
|
|
|
if available_languages:
|
|
selected_lang = st.selectbox("π Select Subtitle Language:", available_languages.keys())
|
|
|
|
if st.button("π₯ Fetch Subtitles"):
|
|
with st.spinner("Fetching subtitles... Please wait β³"):
|
|
time.sleep(2)
|
|
subtitles = get_subtitles(video_id, available_languages[selected_lang])
|
|
study_notes = llm_generator(subtitles=subtitles, api_key=nvidia_api_key)
|
|
|
|
|
|
st.session_state.subtitles = subtitles
|
|
st.session_state.study_notes = study_notes
|
|
|
|
st.success("β
Subtitles and study notes generated successfully!")
|
|
|
|
else:
|
|
st.error("β No subtitles available for this video.")
|
|
else:
|
|
st.error("β Invalid YouTube URL! Please enter a valid link.")
|
|
|
|
|
|
if "subtitles" in st.session_state:
|
|
with st.expander("π View Subtitles (Click to Expand)"):
|
|
st.text_area("Subtitles:", st.session_state.subtitles, height=300)
|
|
|
|
|
|
st.download_button(
|
|
label="β¬οΈ Download Subtitles (.txt)",
|
|
data=st.session_state.subtitles,
|
|
file_name="subtitles.txt",
|
|
mime="text/plain"
|
|
)
|
|
|
|
|
|
st.markdown("## π Study Notes")
|
|
st.write(st.session_state.study_notes)
|
|
|
|
|
|
|
|
file_format = st.radio("Choose Download Format:", ["Text (.txt)", "PDF (.pdf)"])
|
|
|
|
if file_format == "Text (.txt)":
|
|
file_data = st.session_state.study_notes
|
|
file_name = "study_notes.txt"
|
|
mime_type = "text/plain"
|
|
|
|
elif file_format == "PDF (.pdf)":
|
|
pdf = FPDF()
|
|
pdf.add_page()
|
|
pdf.set_font("Arial", size=12)
|
|
pdf.multi_cell(0, 10, st.session_state.study_notes)
|
|
|
|
|
|
pdf_bytes = pdf.output(dest="S").encode("latin1")
|
|
file_data = pdf_bytes
|
|
file_name = "study_notes.pdf"
|
|
mime_type = "application/pdf"
|
|
|
|
|
|
st.download_button(
|
|
label=f"β¬οΈ Download Study Notes ({file_format.split()[1]})",
|
|
data=file_data,
|
|
file_name=file_name,
|
|
mime=mime_type
|
|
)
|
|
|
|
|