-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (35 loc) · 1.27 KB
/
main.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
import logging
import streamlit as st
from config.constants import DEVELOPMENT, MODE
from enums.app import App
from utils.helpers_youtube import is_valid_youtube_url
from views.sidebar import sidebar
st.set_page_config(
page_title="Boteach",
page_icon=":books:",
)
st.title("Boteach")
sidebar()
app: App = st.session_state.get("app")
if not app or MODE == DEVELOPMENT:
app = App()
logging.info("creating new app instance")
st.session_state.app = app
video_url = st.text_input("Paste the youtube url of your lesson", value=app.video)
if video_url and is_valid_youtube_url(video_url):
logging.info(f"valid youtube url: {video_url}")
else:
st.error("invalid youtube url")
st.stop()
app.video = video_url
st.video(app.video, start_time=0)
st.header("Q/A Genie")
user_question = st.text_input("Ask a question about the video:")
submitted = st.button("Submit", type="secondary")
if user_question and submitted:
with st.spinner("LLM Processing"):
response = app.process_question(user_question)
with st.chat_message("ai", avatar="assistant"):
# response.answer = response.answer.replace("[7†source]", "") FIXME: not working
st.markdown(response.answer)
st.video(app.video, start_time=response.start_time)