Spaces:
Runtime error
Runtime error
Commit
·
36f0809
1
Parent(s):
aae00ae
add ½ cup parmesan cheese
Browse files- faiss_store.pkl +3 -0
- main.py +48 -0
faiss_store.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94ca139af5ef2797f275619c44847537ca63620ff0e3533357b5bd68b74f1de1
|
3 |
+
size 4113269
|
main.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Python file to serve as the frontend"""
|
2 |
+
import streamlit as st
|
3 |
+
from streamlit_chat import message
|
4 |
+
import faiss
|
5 |
+
from langchain import OpenAI
|
6 |
+
from langchain.chains import VectorDBQAWithSourcesChain
|
7 |
+
import pickle
|
8 |
+
|
9 |
+
# Load the LangChain.
|
10 |
+
index = faiss.read_index("docs.index")
|
11 |
+
|
12 |
+
with open("faiss_store.pkl", "rb") as f:
|
13 |
+
store = pickle.load(f)
|
14 |
+
|
15 |
+
store.index = index
|
16 |
+
chain = VectorDBQAWithSourcesChain.from_llm(llm=OpenAI(temperature=0), vectorstore=store)
|
17 |
+
|
18 |
+
|
19 |
+
# From here down is all the StreamLit UI.
|
20 |
+
st.set_page_config(page_title="Mekanism and Create Mod QA Bot", page_icon=":robot:")
|
21 |
+
st.header("Mekanism and Create Mod QA Bot")
|
22 |
+
|
23 |
+
if "generated" not in st.session_state:
|
24 |
+
st.session_state["generated"] = []
|
25 |
+
|
26 |
+
if "past" not in st.session_state:
|
27 |
+
st.session_state["past"] = []
|
28 |
+
|
29 |
+
|
30 |
+
def get_text():
|
31 |
+
input_text = st.text_input("You: ", "Hello, how are you?", key="input")
|
32 |
+
return input_text
|
33 |
+
|
34 |
+
|
35 |
+
user_input = get_text()
|
36 |
+
|
37 |
+
if user_input:
|
38 |
+
result = chain({"question": user_input})
|
39 |
+
output = f"Answer: {result['answer']}\nSources: {result['sources']}"
|
40 |
+
|
41 |
+
st.session_state.past.append(user_input)
|
42 |
+
st.session_state.generated.append(output)
|
43 |
+
|
44 |
+
if st.session_state["generated"]:
|
45 |
+
|
46 |
+
for i in range(len(st.session_state["generated"]) - 1, -1, -1):
|
47 |
+
message(st.session_state["generated"][i], key=str(i))
|
48 |
+
message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
|