Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ token=""
|
|
16 |
repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
17 |
emb = "sentence-transformers/all-mpnet-base-v2"
|
18 |
hf = HuggingFaceEmbeddings(model_name=emb)
|
19 |
-
db = Chroma(persist_directory="./chroma_langchain_db")
|
20 |
#db.persist()
|
21 |
# Load the document, split it into chunks, embed each chunk and load it into the vector store.
|
22 |
#raw_documents = TextLoader('state_of_the_union.txt').load()
|
@@ -25,7 +25,7 @@ def embed_fn(inp):
|
|
25 |
documents = text_splitter.split_text(inp)
|
26 |
out_emb= hf.embed_documents(documents)
|
27 |
string_representation = dumps(out_emb, pretty=True)
|
28 |
-
db.from_texts(documents
|
29 |
def proc_doc(doc_in):
|
30 |
for doc in doc_in:
|
31 |
if doc.endswith(".txt"):
|
@@ -57,11 +57,13 @@ def read_pdf(pdf_path):
|
|
57 |
return text
|
58 |
def run_llm(input_text,history):
|
59 |
MAX_TOKENS=20000
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
callbacks = [StreamingStdOutCallbackHandler()]
|
66 |
llm = HuggingFaceEndpoint(
|
67 |
endpoint_url=repo_id,
|
|
|
16 |
repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
17 |
emb = "sentence-transformers/all-mpnet-base-v2"
|
18 |
hf = HuggingFaceEmbeddings(model_name=emb)
|
19 |
+
db = Chroma(persist_directory="./chroma_langchain_db",HuggingFaceEmbeddings(model_name=emb))
|
20 |
#db.persist()
|
21 |
# Load the document, split it into chunks, embed each chunk and load it into the vector store.
|
22 |
#raw_documents = TextLoader('state_of_the_union.txt').load()
|
|
|
25 |
documents = text_splitter.split_text(inp)
|
26 |
out_emb= hf.embed_documents(documents)
|
27 |
string_representation = dumps(out_emb, pretty=True)
|
28 |
+
db.from_texts(documents)
|
29 |
def proc_doc(doc_in):
|
30 |
for doc in doc_in:
|
31 |
if doc.endswith(".txt"):
|
|
|
57 |
return text
|
58 |
def run_llm(input_text,history):
|
59 |
MAX_TOKENS=20000
|
60 |
+
try:
|
61 |
+
qur= hf.embed_query(input_text)
|
62 |
+
docs = db.similarity_search_by_vector(qur, k=3)
|
63 |
+
|
64 |
+
print(docs)
|
65 |
+
except Exception as e:
|
66 |
+
print(e)
|
67 |
callbacks = [StreamingStdOutCallbackHandler()]
|
68 |
llm = HuggingFaceEndpoint(
|
69 |
endpoint_url=repo_id,
|