arjunanand13 commited on
Commit
c95b044
·
verified ·
1 Parent(s): 78fbaa5

Update qa_bot_chatgpt.py

Browse files
Files changed (1) hide show
  1. qa_bot_chatgpt.py +23 -0
qa_bot_chatgpt.py CHANGED
@@ -102,6 +102,29 @@ class QAInfer:
102
  )
103
  return completion.choices[0].message.content
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  if __name__ == '__main__':
107
  qa_infer = QAInfer()
 
102
  )
103
  return completion.choices[0].message.content
104
 
105
+ def qa_infer_interface_gemini(self, row, query_question):
106
+ """This method is used for gradio interface only"""
107
+ file_path = row[-1] # Assuming the last element in row contains the PDF file path
108
+ pdf_text = self.extract_text_from_pdf(file_path)
109
+
110
+ # prompt = f"""Below is a question and context, search the context to find the answer for the question and return the response , if related answer cannot be found return "Answer not in the context" ###question:{query_question} ###context:{pdf_text} ###response:"""
111
+ prompt = f"""You have been provided with a question and a corresponding context. Your task is to search the context to find the answer to the question. If the answer is found, return the response. If the answer cannot be found in the context, please respond with "Answer not found in the context".
112
+
113
+ === Question ===
114
+ {query_question}
115
+
116
+ === Context ===
117
+ {pdf_text}
118
+
119
+ === Response ===
120
+ If related answer is not found return 'Information not present in the pdf' and below it provide something related to the question"""
121
+
122
+ print(prompt)
123
+ completion = self.genai_model.generate_content(prompt)
124
+ generated_answer=completion.text
125
+
126
+ return generated_answer
127
+
128
 
129
  if __name__ == '__main__':
130
  qa_infer = QAInfer()