Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,11 @@ from langchain.llms import OpenAI
|
|
10 |
from langchain.chains.question_answering import load_qa_chain
|
11 |
from langchain.callbacks import get_openai_callback
|
12 |
import os
|
13 |
-
|
|
|
|
|
14 |
# Sidebar contents
|
|
|
15 |
with st.sidebar:
|
16 |
st.title('π€π¬ LLM Chat App')
|
17 |
st.markdown('''
|
@@ -28,7 +31,7 @@ with st.sidebar:
|
|
28 |
|
29 |
# load_dotenv()
|
30 |
|
31 |
-
|
32 |
|
33 |
|
34 |
def main():
|
@@ -62,9 +65,12 @@ def main():
|
|
62 |
VectorStore = pickle.load(f)
|
63 |
# st.write('Embeddings Loaded from the Disk')s
|
64 |
else:
|
65 |
-
embeddings = OpenAIEmbeddings(
|
66 |
-
|
|
|
|
|
67 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
|
|
68 |
with open(f"{store_name}.pkl", "wb") as f:
|
69 |
pickle.dump(VectorStore, f)
|
70 |
|
@@ -77,12 +83,14 @@ def main():
|
|
77 |
|
78 |
if query:
|
79 |
docs = VectorStore.similarity_search(query=query, k=3)
|
80 |
-
|
81 |
-
|
|
|
82 |
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
86 |
st.write(response)
|
87 |
|
88 |
|
|
|
10 |
from langchain.chains.question_answering import load_qa_chain
|
11 |
from langchain.callbacks import get_openai_callback
|
12 |
import os
|
13 |
+
from langchain.vectorstores import Chroma
|
14 |
+
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
|
15 |
+
from langchain.embeddings import HuggingFaceHubEmbeddings
|
16 |
# Sidebar contents
|
17 |
+
from langchain.llms import HuggingFaceHub
|
18 |
with st.sidebar:
|
19 |
st.title('π€π¬ LLM Chat App')
|
20 |
st.markdown('''
|
|
|
31 |
|
32 |
# load_dotenv()
|
33 |
|
34 |
+
os.environ['OPEN_AI_APIKEY'] = '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'
|
35 |
|
36 |
|
37 |
def main():
|
|
|
65 |
VectorStore = pickle.load(f)
|
66 |
# st.write('Embeddings Loaded from the Disk')s
|
67 |
else:
|
68 |
+
# embeddings = OpenAIEmbeddings(
|
69 |
+
# openai_api_key='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')
|
70 |
+
# embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
|
71 |
+
embeddings = HuggingFaceHubEmbeddings()
|
72 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
73 |
+
# VectorStore=Chroma.from_documents(chunks, embeddings)
|
74 |
with open(f"{store_name}.pkl", "wb") as f:
|
75 |
pickle.dump(VectorStore, f)
|
76 |
|
|
|
83 |
|
84 |
if query:
|
85 |
docs = VectorStore.similarity_search(query=query, k=3)
|
86 |
+
llm = HuggingFaceHub(repo_id='OpenAssistant/oasst-sft-1-pythia-12b',
|
87 |
+
token='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', model_kwargs={"temperature": 0.1, "max_new_tokens": 250})
|
88 |
+
# llm = OpenAI()
|
89 |
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
90 |
+
response = chain.run(input_documents=docs, question=query)
|
91 |
+
# with get_openai_callback() as cb:
|
92 |
+
# response = chain.run(input_documents=docs, question=query)
|
93 |
+
# print(cb)
|
94 |
st.write(response)
|
95 |
|
96 |
|