Pavan178 commited on
Commit
91326a4
·
verified ·
1 Parent(s): b3de9a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -69,34 +69,29 @@ class AdvancedPdfChatbot:
69
 
70
  self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
71
 
72
- class CustomChain(Chain):
73
  def __init__(self, refinement_chain, qa_chain):
74
- """Initialize refinement and QA chains as instance attributes."""
75
  super().__init__()
76
- self._refinement_chain = refinement_chain # Use a different attribute name
77
  self._qa_chain = qa_chain
78
-
79
  @property
80
  def input_keys(self):
81
- """Define the input keys that this chain expects."""
82
  return ["query", "chat_history"]
83
-
84
  @property
85
  def output_keys(self):
86
- """Define the output keys that this chain returns."""
87
  return ["answer"]
88
-
89
  def _call(self, inputs):
90
  query = inputs['query']
91
  chat_history = inputs.get('chat_history', [])
92
 
93
- # Run the refinement chain to refine the query
94
  refinement_inputs = {'query': query, 'chat_history': chat_history}
95
- refined_query = self._refinement_chain.run(refinement_inputs) # Use the renamed attribute
96
 
97
- # Run the QA chain using the refined query and the chat history
98
  qa_inputs = {"question": refined_query, "chat_history": chat_history}
99
- response = self._qa_chain(qa_inputs) # Use the renamed attribute
100
 
101
  return {"answer": response['answer']}
102
 
@@ -158,4 +153,4 @@ with gr.Blocks() as demo:
158
  msg.submit(respond, inputs=[msg, chatbot_interface], outputs=[msg, chatbot_interface])
159
 
160
  if __name__ == "__main__":
161
- demo.launch()
 
69
 
70
  self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
71
 
72
+ class CustomChain(Chain):
73
  def __init__(self, refinement_chain, qa_chain):
 
74
  super().__init__()
75
+ self._refinement_chain = refinement_chain
76
  self._qa_chain = qa_chain
77
+
78
  @property
79
  def input_keys(self):
 
80
  return ["query", "chat_history"]
81
+
82
  @property
83
  def output_keys(self):
 
84
  return ["answer"]
85
+
86
  def _call(self, inputs):
87
  query = inputs['query']
88
  chat_history = inputs.get('chat_history', [])
89
 
 
90
  refinement_inputs = {'query': query, 'chat_history': chat_history}
91
+ refined_query = self._refinement_chain.run(refinement_inputs)
92
 
 
93
  qa_inputs = {"question": refined_query, "chat_history": chat_history}
94
+ response = self._qa_chain(qa_inputs)
95
 
96
  return {"answer": response['answer']}
97
 
 
153
  msg.submit(respond, inputs=[msg, chatbot_interface], outputs=[msg, chatbot_interface])
154
 
155
  if __name__ == "__main__":
156
+ demo.launch()