Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
import tempfile
|
3 |
-
import pandas as pd
|
4 |
-
from langchain import HuggingFacePipeline
|
5 |
-
from transformers import AutoTokenizer
|
6 |
-
from langchain.embeddings import HuggingFaceEmbeddings
|
7 |
-
from langchain.document_loaders.csv_loader import CSVLoader
|
8 |
-
from langchain.vectorstores import FAISS
|
9 |
-
from langchain.chains import RetrievalQA
|
10 |
-
import transformers
|
11 |
-
import torch
|
12 |
-
import textwrap
|
13 |
|
14 |
def main():
|
15 |
st.set_page_config(page_title="Talk with BORROWER data")
|
@@ -19,32 +19,25 @@ def main():
|
|
19 |
if st.button("Submit Query", type="primary"):
|
20 |
DB_FAISS_PATH = "vectorstore/db_faiss"
|
21 |
|
22 |
-
|
23 |
loader = CSVLoader(file_path="./borrower_data.csv", encoding="utf-8", csv_args={
|
24 |
'delimiter': ','})
|
25 |
data = loader.load()
|
26 |
|
27 |
-
model = "daryl149/llama-2-7b-chat-hf"
|
28 |
-
tokenizer = AutoTokenizer.from_pretrained(model)
|
29 |
-
pipeline = transformers.pipeline("text-generation",
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
trust_remote_code=True,
|
34 |
-
device_map="auto",
|
35 |
-
do_sample=True,
|
36 |
-
top_k=1,
|
37 |
-
num_return_sequences=1,
|
38 |
-
eos_token_id=tokenizer.eos_token_id
|
39 |
-
)
|
40 |
-
|
41 |
-
llm = HuggingFacePipeline(pipeline = pipeline, model_kwargs = {'temperature':0})
|
42 |
-
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
|
43 |
vectorstore = FAISS.from_documents(data, embeddings)
|
44 |
vectorstore.save_local(DB_FAISS_PATH)
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
st.write(result['result'])
|
48 |
|
49 |
if __name__ == '__main__':
|
50 |
-
main()
|
|
|
1 |
import streamlit as st
|
2 |
import tempfile
|
3 |
+
import pandas as pd
|
4 |
+
from langchain import HuggingFacePipeline
|
5 |
+
from transformers import AutoTokenizer
|
6 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
7 |
+
from langchain.document_loaders.csv_loader import CSVLoader
|
8 |
+
from langchain.vectorstores import FAISS
|
9 |
+
from langchain.chains import RetrievalQA
|
10 |
+
import transformers
|
11 |
+
import torch
|
12 |
+
import textwrap
|
13 |
|
14 |
def main():
|
15 |
st.set_page_config(page_title="Talk with BORROWER data")
|
|
|
19 |
if st.button("Submit Query", type="primary"):
|
20 |
DB_FAISS_PATH = "vectorstore/db_faiss"
|
21 |
|
|
|
22 |
loader = CSVLoader(file_path="./borrower_data.csv", encoding="utf-8", csv_args={
|
23 |
'delimiter': ','})
|
24 |
data = loader.load()
|
25 |
|
26 |
+
model = "daryl149/llama-2-7b-chat-hf"
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
28 |
+
pipeline = transformers.pipeline("text-generation", model=model, tokenizer=tokenizer, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto", do_sample=True, top_k=1, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
|
29 |
+
|
30 |
+
llm = HuggingFacePipeline(pipeline=pipeline, model_kwargs={'temperature': 0})
|
31 |
+
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
vectorstore = FAISS.from_documents(data, embeddings)
|
33 |
vectorstore.save_local(DB_FAISS_PATH)
|
34 |
+
|
35 |
+
# Load the saved vectorstore
|
36 |
+
vectorstore = FAISS.load_local(DB_FAISS_PATH, embeddings)
|
37 |
+
|
38 |
+
chain = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", return_source_documents=True, retriever=vectorstore.as_retriever())
|
39 |
+
result = chain(query)
|
40 |
st.write(result['result'])
|
41 |
|
42 |
if __name__ == '__main__':
|
43 |
+
main()
|