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