Spaces:
Runtime error
Runtime error
fakezeta
commited on
Commit
·
88278c4
1
Parent(s):
6feb027
cleaned comments
Browse files- app.py +0 -1
- ingest_data.py +0 -5
- query_data.py +1 -24
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
from ast import Delete
|
2 |
import streamlit as st
|
3 |
from streamlit_chat import message
|
4 |
from ingest_data import embed_doc
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from streamlit_chat import message
|
3 |
from ingest_data import embed_doc
|
ingest_data.py
CHANGED
@@ -25,13 +25,8 @@ def embed_doc(filename):
|
|
25 |
st.text("Load and split text: "+str(round(end - start,1)))
|
26 |
|
27 |
|
28 |
-
# Load Data to vectorstore
|
29 |
start = time.time()
|
30 |
-
# embeddings = LlamaCppEmbeddings(model_path="ggml-model.bin")
|
31 |
-
# embeddings = HuggingFaceEmbeddings(model_name="diptanuc/all-mpnet-base-v2", model_kwargs={'device': 'cpu'})
|
32 |
-
# embeddings = TensorflowHubEmbeddings(model_url="https://tfhub.dev/google/universal-sentence-encoder/4")
|
33 |
embeddings = TensorflowHubEmbeddings(model_url="https://tfhub.dev/google/universal-sentence-encoder-multilingual-qa/3")
|
34 |
-
# embeddings = HuggingFaceEmbeddings(model_name="obrizum/all-MiniLM-L6-v2", model_kwargs={'device': 'cpu'})
|
35 |
end = time.time()
|
36 |
st.text("Embedding time: "+str(round(end - start,1)))
|
37 |
start = time.time()
|
|
|
25 |
st.text("Load and split text: "+str(round(end - start,1)))
|
26 |
|
27 |
|
|
|
28 |
start = time.time()
|
|
|
|
|
|
|
29 |
embeddings = TensorflowHubEmbeddings(model_url="https://tfhub.dev/google/universal-sentence-encoder-multilingual-qa/3")
|
|
|
30 |
end = time.time()
|
31 |
st.text("Embedding time: "+str(round(end - start,1)))
|
32 |
start = time.time()
|
query_data.py
CHANGED
@@ -1,40 +1,17 @@
|
|
1 |
-
from langchain.prompts.prompt import PromptTemplate
|
2 |
from langchain.llms import LlamaCpp
|
3 |
from langchain.chains import ConversationalRetrievalChain
|
4 |
-
from langchain.memory import ConversationBufferMemory
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
|
7 |
import psutil
|
8 |
import os
|
9 |
|
10 |
-
#_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
|
11 |
-
#You can assume the question about the uploaded document.
|
12 |
|
13 |
-
#Chat History:
|
14 |
-
#{chat_history}
|
15 |
-
#Follow Up Input: {question}
|
16 |
-
#Standalone question:"""
|
17 |
-
#CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
|
18 |
-
|
19 |
-
#template = """You are an AI assistant for answering questions about the uploaded document.
|
20 |
-
#You are given the following extracted parts of a long document and a question. Provide a conversational answer.
|
21 |
-
#If you don't know the answer, just say "Hmm, I'm not sure." Don't try to make up an answer.
|
22 |
-
#If the question is not about the uploaded document, politely inform them that you are tuned to only answer questions about the uploaded document.
|
23 |
-
#Question: {question}
|
24 |
-
|
25 |
-
#Answer in Markdown:"""
|
26 |
-
##QA_PROMPT = PromptTemplate(template=template, input_variables=["question", "context"])
|
27 |
-
#QA_PROMPT = PromptTemplate(template=template, input_variables=["question"])
|
28 |
-
|
29 |
-
#=========
|
30 |
-
#{context}
|
31 |
-
#=========
|
32 |
|
33 |
|
34 |
def get_chain(vectorstore):
|
35 |
if not os.path.exists("ggml-vic7b-q5_1.bin"):
|
36 |
hf_hub_download(repo_id="eachadea/ggml-vicuna-7b-1.1", filename="ggml-vic7b-q5_1.bin", local_dir=".")
|
37 |
-
llm = LlamaCpp(model_path="ggml-vic7b-q5_1.bin", n_ctx=2048, n_threads=psutil.cpu_count(logical=False)
|
38 |
qa_chain = ConversationalRetrievalChain.from_llm(
|
39 |
llm,
|
40 |
vectorstore.as_retriever(),
|
|
|
|
|
1 |
from langchain.llms import LlamaCpp
|
2 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
|
5 |
import psutil
|
6 |
import os
|
7 |
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
def get_chain(vectorstore):
|
12 |
if not os.path.exists("ggml-vic7b-q5_1.bin"):
|
13 |
hf_hub_download(repo_id="eachadea/ggml-vicuna-7b-1.1", filename="ggml-vic7b-q5_1.bin", local_dir=".")
|
14 |
+
llm = LlamaCpp(model_path="ggml-vic7b-q5_1.bin", n_ctx=2048, n_threads=psutil.cpu_count(logical=False))
|
15 |
qa_chain = ConversationalRetrievalChain.from_llm(
|
16 |
llm,
|
17 |
vectorstore.as_retriever(),
|