Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,6 @@ login(token=hf_token, add_to_git_credential=True)
|
|
21 |
openai_key = os.environ["OPENAI_API_KEY"]
|
22 |
|
23 |
|
24 |
-
# Define the template
|
25 |
template = PromptTemplate(
|
26 |
prompt="""
|
27 |
Answer the given question using the following documents. \
|
@@ -30,7 +29,7 @@ Provide example quotes and citations using extracted text from the documents. \
|
|
30 |
Use facts and numbers from the documents in your answer. \
|
31 |
Reference information used from documents at the end of each applicable sentence (ex: [source: document_name]), where 'document_name' is the text provided at the start of each document (demarcated by '- &&&' and '&&&:')'. \
|
32 |
If no relevant information to answer the question is present in the documents, just say you don't have enough information to answer. \
|
33 |
-
Context: {' - '.join(['&&& '+d.meta['
|
34 |
)
|
35 |
|
36 |
# Create a list of options for the dropdown
|
@@ -74,7 +73,7 @@ def get_docs(input_query, country = None):
|
|
74 |
# Create a Document object for each row
|
75 |
doc = Document(
|
76 |
row['content'],
|
77 |
-
meta={'country': row['country'],'
|
78 |
)
|
79 |
|
80 |
# Append the Document object to the documents list
|
@@ -97,7 +96,7 @@ def get_refs(docs, res):
|
|
97 |
doc = docs[i].to_dict()
|
98 |
ref_id = doc['meta']['ref_id']
|
99 |
if ref_id in ref_ids:
|
100 |
-
result_str += "**Ref. " + str(ref_id) + " [" + doc['meta']['country'] + " " + doc['meta']['
|
101 |
|
102 |
return result_str
|
103 |
|
|
|
21 |
openai_key = os.environ["OPENAI_API_KEY"]
|
22 |
|
23 |
|
|
|
24 |
template = PromptTemplate(
|
25 |
prompt="""
|
26 |
Answer the given question using the following documents. \
|
|
|
29 |
Use facts and numbers from the documents in your answer. \
|
30 |
Reference information used from documents at the end of each applicable sentence (ex: [source: document_name]), where 'document_name' is the text provided at the start of each document (demarcated by '- &&&' and '&&&:')'. \
|
31 |
If no relevant information to answer the question is present in the documents, just say you don't have enough information to answer. \
|
32 |
+
Context: {' - '.join(['&&& '+d.meta['document']+' ref. '+str(d.meta['ref_id'])+' &&&: '+d.content for d in documents])}; Question: {query}; Answer:""",
|
33 |
)
|
34 |
|
35 |
# Create a list of options for the dropdown
|
|
|
73 |
# Create a Document object for each row
|
74 |
doc = Document(
|
75 |
row['content'],
|
76 |
+
meta={'country': row['country'],'document': row['document'], 'page': row['page'], 'file_name': row['file_name'], 'ref_id': row['ref_id'], 'score': row['score']}
|
77 |
)
|
78 |
|
79 |
# Append the Document object to the documents list
|
|
|
96 |
doc = docs[i].to_dict()
|
97 |
ref_id = doc['meta']['ref_id']
|
98 |
if ref_id in ref_ids:
|
99 |
+
result_str += "**Ref. " + str(ref_id) + " [" + doc['meta']['country'] + " " + doc['meta']['document'] + ' p' + str(doc['meta']['page']) + "]:** " + "*'" + doc['content'] + "'*<br> <br>" # Add <br> for a line break
|
100 |
|
101 |
return result_str
|
102 |
|