-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_streamlit.py
54 lines (41 loc) · 1.53 KB
/
main_streamlit.py
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
"""
## Main streamlit file
The main frontend file to run the application.
Execute :
`streamlit run main_streamlit.py`
to run the application
"""
import streamlit as st
import embedding_generator as emb
# Main application
st.title("YouTube Assistant 🤖")
# Initialize session state for the YouTube URL and database
if "yt_url" not in st.session_state:
st.session_state["yt_url"] = None
st.session_state["db"] = None
st.session_state["thumbnail"] = None
# Side bar
with st.sidebar:
with st.form(key="form"):
yt_url = st.text_input(
label="📽️ YouTube Video URL",
)
query = st.text_area(label="Ask me about the video ❓", max_chars=60)
submit_btn = st.form_submit_button()
# On submit button click!
if submit_btn:
if not (query and yt_url):
st.error("Please Enter Video URL and Question both.")
else:
# Check if the URL has changed
if yt_url != st.session_state["yt_url"]:
# If URL is new, update the session state and create a new vector database
st.session_state["yt_url"] = yt_url
st.session_state["db"], st.session_state["thumbnail"] = emb.create_vector_db_from_yt_url(yt_url)
if st.session_state["thumbnail"]:
st.image(st.session_state["thumbnail"], width=400)
st.subheader("User : " + query)
# Use the stored db from session state
response = emb.get_response(query, st.session_state["db"])
# st.text("Answer :")
st.write_stream(response)