Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,46 +12,41 @@ import torch
|
|
12 |
import textwrap
|
13 |
|
14 |
def main():
|
15 |
-
st.set_page_config(page_title="
|
16 |
-
st.title("
|
17 |
uploaded_file = st.sidebar.file_uploader("Upload your Data", type="csv")
|
18 |
|
19 |
query = st.text_input("Send a Message")
|
20 |
if st.button("Submit Query", type="primary"):
|
21 |
DB_FAISS_PATH = "vectorstore/db_faiss"
|
22 |
|
23 |
-
if uploaded_file :
|
24 |
-
#use tempfile because CSVLoader only accepts a file_path
|
25 |
-
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
26 |
-
tmp_file.write(uploaded_file.getvalue())
|
27 |
-
tmp_file_path = tmp_file.name
|
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 |
if __name__ == '__main__':
|
57 |
main()
|
|
|
12 |
import textwrap
|
13 |
|
14 |
def main():
|
15 |
+
st.set_page_config(page_title="Talk with BORROWER data")
|
16 |
+
st.title("Talk with BORROWER data")
|
17 |
uploaded_file = st.sidebar.file_uploader("Upload your Data", type="csv")
|
18 |
|
19 |
query = st.text_input("Send a Message")
|
20 |
if st.button("Submit Query", type="primary"):
|
21 |
DB_FAISS_PATH = "vectorstore/db_faiss"
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
loader = CSVLoader(file_path="./borrower_data.csv", encoding="utf-8", csv_args={
|
25 |
+
'delimiter': ','})
|
26 |
+
data = loader.load()
|
27 |
+
st.write(data)
|
28 |
|
29 |
+
model = "daryl149/llama-2-7b-chat-hf"
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
31 |
+
pipeline = transformers.pipeline("text-generation", #task
|
32 |
+
model=model,
|
33 |
+
tokenizer=tokenizer,
|
34 |
+
torch_dtype=torch.bfloat16,
|
35 |
+
trust_remote_code=True,
|
36 |
+
device_map="auto",
|
37 |
+
do_sample=True,
|
38 |
+
top_k=5,
|
39 |
+
num_return_sequences=1,
|
40 |
+
eos_token_id=tokenizer.eos_token_id
|
41 |
+
)
|
42 |
|
43 |
+
llm = HuggingFacePipeline(pipeline = pipeline, model_kwargs = {'temperature':0})
|
44 |
+
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
|
45 |
+
vectorstore = FAISS.from_documents(data, embeddings)
|
46 |
+
vectorstore.save_local(DB_FAISS_PATH)
|
47 |
+
chain=retrievalQA.from_chain_type(llm=llm, chain_type = "stuff",return_source_documents=True, retriever=vectorstore.as_retriever())
|
48 |
+
result=chain(query)
|
49 |
+
st.write(result['result'])
|
50 |
|
51 |
if __name__ == '__main__':
|
52 |
main()
|