Update app.py
Browse files
app.py
CHANGED
|
@@ -44,37 +44,40 @@ def 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 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
)
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
-
context = get_context(query, collection)
|
|
|
|
|
|
|
| 74 |
|
| 75 |
print(context)
|
| 76 |
print('calling local query')
|
| 77 |
-
result = local_query(query, context)
|
|
|
|
| 78 |
print('printing result after call back')
|
| 79 |
print(result)
|
| 80 |
print(history)
|
|
@@ -83,7 +86,7 @@ def run_query(btn, history, query):
|
|
| 83 |
|
| 84 |
print('printing history')
|
| 85 |
print(history)
|
| 86 |
-
return
|
| 87 |
|
| 88 |
|
| 89 |
|
|
@@ -118,7 +121,7 @@ with gr.Blocks() as demo:
|
|
| 118 |
|
| 119 |
# Event handler for uploading a PDF
|
| 120 |
btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
|
| 121 |
-
txt.submit(run_query, [btn, chatbot, txt], [
|
| 122 |
#.then(
|
| 123 |
# generate_response, inputs =[chatbot,],outputs = chatbot,)
|
| 124 |
|
|
|
|
| 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 |
+
|
| 75 |
+
|
| 76 |
|
| 77 |
print(context)
|
| 78 |
print('calling local query')
|
| 79 |
+
# result = local_query(query, context)
|
| 80 |
+
result = 'heleleoeppepepppepepe'
|
| 81 |
print('printing result after call back')
|
| 82 |
print(result)
|
| 83 |
print(history)
|
|
|
|
| 86 |
|
| 87 |
print('printing history')
|
| 88 |
print(history)
|
| 89 |
+
return history, ""
|
| 90 |
|
| 91 |
|
| 92 |
|
|
|
|
| 121 |
|
| 122 |
# Event handler for uploading a PDF
|
| 123 |
btn.upload(fn=upload_pdf, inputs=[btn], outputs=[output])
|
| 124 |
+
txt.submit(run_query, [btn, chatbot, txt], [chatbot, txt])
|
| 125 |
#.then(
|
| 126 |
# generate_response, inputs =[chatbot,],outputs = chatbot,)
|
| 127 |
|