-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
98 lines (79 loc) · 3.61 KB
/
Copy pathapp.py
File metadata and controls
98 lines (79 loc) · 3.61 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
from streamlit import spinner
from streamlit.web.server.server import server_port_is_manually_set
from supporting_functions import (
extract_video_id,
get_transcript,
translate_transcript,
generate_notes,
create_chunks,
create_vector_store,
rag_answer
)
# --- Sidebar (Inputs) ---
if "messages" not in st.session_state:
st.session_state["messages"] = []
with st.sidebar:
st.title(" VidSynth AI")
st.markdown("---")
st.markdown("Transform any YouTube video into key topics, a podcast, or a chatbot.")
st.markdown("### Input Details")
youtube_url = st.text_input("YouTube URL", placeholder="https://www.youtube.com/watch?v=...")
language = st.text_input("Video Language Code", placeholder="e.g., en, hi, es, fr", value="en")
task_option = st.radio(
"Choose what you want to generate:",
["Chat with Video", "Notes For You"]
)
submit_button = st.button(" Start Processing")
st.markdown("---")
# The "New Chat" button has been removed from here.
# --- Main Page ---
st.title("YouTube Content Synthesizer")
st.markdown("Paste a video link and select a task from the sidebar.")
# --- Processing Flow ---
if submit_button:
if youtube_url and language:
video_id= extract_video_id(youtube_url)
if video_id:
# Reset chat state when switching to a different video
if st.session_state.get("current_video_id") != video_id:
st.session_state.pop("vector_store", None)
st.session_state["messages"] = []
with spinner("Step 1/3 : Fetching Transcript....."):
full_transcript= get_transcript(video_id, language)
if language!="en":
with spinner("Step 1.5/3 : Translating Transcript into English, This may take few moments......"):
full_transcript= translate_transcript(full_transcript)
if task_option=="Notes For You":
with spinner("Step 2/3: Extracting important Topics..."):
import_topics= get_important_topics(full_transcript)
st.subheader("Important Topics")
st.write(import_topics)
st.markdown("---")
with spinner("Step 3/3 : Generating Notes for you."):
notes= generate_notes(full_transcript)
st.subheader("Notes for you")
st.write(notes)
st.success("Summary and Notes Generated.")
if task_option == "Chat with Video":
with st.spinner("Step 2/3: Creating chunks and vector store...."):
chunks = create_chunks(full_transcript)
vectorstore = create_vector_store(chunks)
st.session_state.vector_store = vectorstore
st.session_state.messages=[]
st.session_state["current_video_id"] = video_id
st.success('Video is ready for chat.....')
# Display the entire history
for message in st.session_state.get('messages',[]):
with st.chat_message(message['role']):
st.write(message['content'])
# user_input
prompt= st.chat_input("Ask me anything about the video.")
if prompt:
st.session_state.messages.append({'role':'user','content':prompt})
with st.chat_message('user'):
st.write(prompt)
with st.chat_message('assistant'):
response= rag_answer(prompt,st.session_state.vector_store)
st.write(response)
st.session_state.messages.append({'role': 'assistant', 'content':response})