-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (45 loc) · 2.04 KB
/
app.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
55
56
57
58
59
60
61
62
from src.LLM import LLM
from src.PromptParser import PromptParser
from src.YoutubeHelper import search
from src.Data import Data
from src.RAG import Database
import streamlit as st
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
st.session_state.llm = None
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("Message GlancyAI"):
# Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
if not st.session_state.llm:
with st.chat_message('assistant'):
with st.status("Processing..."):
st.write("Analysing Requirements...")
prompt_parser = PromptParser()
ini_llm = LLM(system=prompt_parser.get('youtube_query'))
query = ini_llm.call(prompt, tool_choice='required')
st.write(f"Searching YouTube ({query})...")
results_dict = search(query, max_results=50)
st.write(f"Retrieved {len(results_dict)} videos from YouTube.")
data = Data(results_dict)
data.filter(count=10, min_latest=5)
st.write(f"Builing Vector Space (acquired {len(data.data)})...")
database = Database(data.data)
st.write(f"Powering up the LLM...")
st.session_state.llm = LLM(db=database)
st.markdown("Ask away!")
else:
response = st.session_state.llm.call(prompt)
# Display assistant response in chat message container
with st.chat_message("assistant"):
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})