-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (29 loc) · 1.33 KB
/
Copy pathapp.py
File metadata and controls
38 lines (29 loc) · 1.33 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
from getData import getData
from elasticSearch import createIndex, elastic_search
from mistralAI import build_prompt, llm
import streamlit as st
from stqdm import stqdm
st.title("DataTalks FAQ Chatbot")
# Initialize session state for data and esclient
def initialize_data():
if 'data_initialized' not in st.session_state:
st.session_state.documents = getData()
st.session_state.index_name = "course-questions"
st.session_state.esclient = createIndex(st.session_state.index_name)
with st.spinner('Preparing the data...'):
for doc in stqdm(st.session_state.documents):
# input the data to elastic search
st.session_state.esclient.index(index=st.session_state.index_name, document=doc)
st.session_state.data_initialized = True
# Initialize data only if not already done
if 'data_initialized' not in st.session_state:
initialize_data()
with st.form("my_form"):
query = st.text_input("Input Question", "tell me more about the course")
submitted = st.form_submit_button("Submit")
if submitted:
with st.spinner('Preparing the answer...'):
search_result = elastic_search(st.session_state.esclient, query, st.session_state.index_name)
prompt = build_prompt(query, search_result)
response = llm(prompt)
st.write(response)