Spaces:
Sleeping
Sleeping
apahilaj
commited on
Commit
·
14af323
1
Parent(s):
b11ca01
fix error
Browse files
app.py
CHANGED
@@ -61,12 +61,12 @@ def load_db(file, k):
|
|
61 |
def chat(input_text, pdf_file):
|
62 |
qa = load_db(pdf_file, 3)
|
63 |
|
64 |
-
if not memory.
|
65 |
# If no previous conversation, start with a greeting
|
66 |
response = qa.invoke({"question": "Hi, how can I help you today?", "chat_history": []})
|
67 |
memory.update(response["chat_history"])
|
68 |
|
69 |
-
response = qa.invoke({"question": input_text, "chat_history": memory.
|
70 |
|
71 |
# Extracting the helpful answer from the response
|
72 |
match = re.search(r'Helpful Answer:(.*)', response['answer'])
|
@@ -78,14 +78,7 @@ def chat(input_text, pdf_file):
|
|
78 |
# Update the chat history
|
79 |
memory.update([(input_text, helpful_answer)])
|
80 |
|
81 |
-
|
82 |
-
output_text = f"Question: {input_text}\nAnswer: {helpful_answer}\nGenerated Question: {response['generated_question']}\nSource Documents: {response['source_documents']}"
|
83 |
-
|
84 |
-
return output_text
|
85 |
-
|
86 |
-
|
87 |
|
88 |
iface = gr.Interface(fn=chat, inputs=["text", "file"], outputs="text")
|
89 |
iface.launch(share=True)
|
90 |
-
|
91 |
-
|
|
|
61 |
def chat(input_text, pdf_file):
|
62 |
qa = load_db(pdf_file, 3)
|
63 |
|
64 |
+
if not memory.memory_buffer:
|
65 |
# If no previous conversation, start with a greeting
|
66 |
response = qa.invoke({"question": "Hi, how can I help you today?", "chat_history": []})
|
67 |
memory.update(response["chat_history"])
|
68 |
|
69 |
+
response = qa.invoke({"question": input_text, "chat_history": memory.memory_buffer})
|
70 |
|
71 |
# Extracting the helpful answer from the response
|
72 |
match = re.search(r'Helpful Answer:(.*)', response['answer'])
|
|
|
78 |
# Update the chat history
|
79 |
memory.update([(input_text, helpful_answer)])
|
80 |
|
81 |
+
return helpful_answer
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
iface = gr.Interface(fn=chat, inputs=["text", "file"], outputs="text")
|
84 |
iface.launch(share=True)
|
|
|
|