Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -63,17 +63,17 @@ def clear_file_fn():
|
|
| 63 |
return None, None
|
| 64 |
|
| 65 |
|
| 66 |
-
def retrieve_document_fn(question, document_data, document_index):
|
| 67 |
num_retrieval_doc = 3
|
| 68 |
if document_index is None or document_data is None:
|
| 69 |
gr.Warning("Please upload documents first!")
|
| 70 |
return [None for i in range(num_retrieval_doc)]
|
| 71 |
|
| 72 |
-
question_embedding = model.encode([question])
|
| 73 |
batch_scores, batch_inxs = document_index.search(question_embedding, k=num_retrieval_doc)
|
| 74 |
|
| 75 |
answers = [document_data[i]["text"] for i in batch_inxs[0][:num_retrieval_doc]]
|
| 76 |
-
return
|
| 77 |
|
| 78 |
|
| 79 |
def main(args):
|
|
@@ -98,8 +98,8 @@ def main(args):
|
|
| 98 |
retrieval_interface = gr.Interface(
|
| 99 |
fn=retrieve_document_fn,
|
| 100 |
inputs=["text"],
|
| 101 |
-
outputs=["text", "text", "text"],
|
| 102 |
-
additional_inputs=[document_data, document_index],
|
| 103 |
concurrency_limit=1,
|
| 104 |
)
|
| 105 |
|
|
|
|
| 63 |
return None, None
|
| 64 |
|
| 65 |
|
| 66 |
+
def retrieve_document_fn(question, instruct, document_data, document_index):
|
| 67 |
num_retrieval_doc = 3
|
| 68 |
if document_index is None or document_data is None:
|
| 69 |
gr.Warning("Please upload documents first!")
|
| 70 |
return [None for i in range(num_retrieval_doc)]
|
| 71 |
|
| 72 |
+
question_embedding = model.encode([instruct + question])
|
| 73 |
batch_scores, batch_inxs = document_index.search(question_embedding, k=num_retrieval_doc)
|
| 74 |
|
| 75 |
answers = [document_data[i]["text"] for i in batch_inxs[0][:num_retrieval_doc]]
|
| 76 |
+
return answers[0], answers[1], answers[2], document_data, document_index
|
| 77 |
|
| 78 |
|
| 79 |
def main(args):
|
|
|
|
| 98 |
retrieval_interface = gr.Interface(
|
| 99 |
fn=retrieve_document_fn,
|
| 100 |
inputs=["text"],
|
| 101 |
+
outputs=["text", "text", "text", gr.State(), gr.State()],
|
| 102 |
+
additional_inputs=[gr.Textbox("Instruct: Given a query, retrieve documents that answer the query. \n Query: ", label="Instruct of Query"), document_data, document_index],
|
| 103 |
concurrency_limit=1,
|
| 104 |
)
|
| 105 |
|