Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,9 +86,16 @@ def conversation(qa_chain, message, history):
|
|
86 |
response = qa_chain({"question": message, "chat_history": formatted_chat_history})
|
87 |
response_answer = response["answer"].split("Helpful Answer:")[-1]
|
88 |
response_sources = response["source_documents"]
|
89 |
-
sources = [(source.page_content.strip(), source.metadata["page"] + 1) for source in response_sources[:5]]
|
90 |
new_history = history + [(message, response_answer)]
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
def demo():
|
94 |
with gr.Blocks(theme="base") as demo:
|
|
|
86 |
response = qa_chain({"question": message, "chat_history": formatted_chat_history})
|
87 |
response_answer = response["answer"].split("Helpful Answer:")[-1]
|
88 |
response_sources = response["source_documents"]
|
89 |
+
sources = [(source.page_content.strip(), source.metadata["page"] + 1) for source in response_sources[:5]]
|
90 |
new_history = history + [(message, response_answer)]
|
91 |
+
|
92 |
+
# Ensure we always return 5 sources and 5 pages
|
93 |
+
source_texts = [source[0] for source in sources] + [''] * (5 - len(sources))
|
94 |
+
source_pages = [source[1] for source in sources] + [0] * (5 - len(sources))
|
95 |
+
|
96 |
+
return (qa_chain, gr.update(value=""), new_history,
|
97 |
+
*source_texts[:5], # Unpack exactly 5 source texts
|
98 |
+
*source_pages[:5]) # Unpack exactly 5 source pages
|
99 |
|
100 |
def demo():
|
101 |
with gr.Blocks(theme="base") as demo:
|