Update app.py
Browse files
app.py
CHANGED
|
@@ -44,34 +44,34 @@ def local_query(query, context):
|
|
| 44 |
|
| 45 |
def run_query(btn, history, query):
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
-
|
| 74 |
-
context = 'My name is damla'
|
| 75 |
|
| 76 |
print('calling local query')
|
| 77 |
result = local_query(query, context)
|
|
|
|
| 44 |
|
| 45 |
def run_query(btn, history, query):
|
| 46 |
|
| 47 |
+
file_name = btn.name
|
| 48 |
|
| 49 |
+
loader = PDFMinerLoader(file_name)
|
| 50 |
+
doc = loader.load()
|
| 51 |
|
| 52 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 53 |
+
texts = text_splitter.split_documents(doc)
|
| 54 |
|
| 55 |
+
texts = [i.page_content for i in texts]
|
| 56 |
|
| 57 |
+
doc_emb = st_model.encode(texts)
|
| 58 |
+
doc_emb = doc_emb.tolist()
|
| 59 |
|
| 60 |
+
ids = [str(uuid.uuid1()) for _ in doc_emb]
|
| 61 |
|
| 62 |
+
client = chromadb.Client()
|
| 63 |
+
collection = client.create_collection("test_db")
|
| 64 |
|
| 65 |
+
collection.add(
|
| 66 |
+
embeddings=doc_emb,
|
| 67 |
+
documents=texts,
|
| 68 |
+
ids=ids
|
| 69 |
+
)
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
+
context = get_context(query, collection)
|
| 74 |
+
# context = 'My name is damla'
|
| 75 |
|
| 76 |
print('calling local query')
|
| 77 |
result = local_query(query, context)
|