ppsingh commited on
Commit
488567e
1 Parent(s): a5d5a26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -200,31 +200,25 @@ async def chat(query,history,sources,reports,subtype,year):
200
  # create rag chain
201
  chat_model = ChatHuggingFace(llm=llm_qa)
202
  chain = chat_model | StrOutputParser()
203
-
204
- try:
205
- async for op in result:
206
-
207
- ###-------------------------- get answers ---------------------------------------
208
- answer_lst = []
209
- for question, context in zip(question_lst , context_retrieved_lst):
210
- answer = chain.invoke(messages)
211
- answer_lst.append(answer)
212
- docs_html = []
213
- for i, d in enumerate(context_retrieved, 1):
214
- docs_html.append(make_html_source(d, i))
215
- docs_html = "".join(docs_html)
 
 
 
 
216
 
217
- previous_answer = history[-1][1]
218
- previous_answer = previous_answer if previous_answer is not None else ""
219
- answer_yet = previous_answer + answer_lst[0]
220
- answer_yet = parse_output_llm_with_sources(answer_yet)
221
- history[-1] = (query,answer_yet)
222
-
223
- history = [tuple(x) for x in history]
224
-
225
- yield history,docs_html
226
- except Exception as e:
227
- raise gr.Error(f"{e}")
228
  #process_pdf()
229
 
230
 
 
200
  # create rag chain
201
  chat_model = ChatHuggingFace(llm=llm_qa)
202
  chain = chat_model | StrOutputParser()
203
+ ###-------------------------- get answers ---------------------------------------
204
+ answer_lst = []
205
+ for question, context in zip(question_lst , context_retrieved_lst):
206
+ answer = chain.invoke(messages)
207
+ answer_lst.append(answer)
208
+ docs_html = []
209
+ for i, d in enumerate(context_retrieved, 1):
210
+ docs_html.append(make_html_source(d, i))
211
+ docs_html = "".join(docs_html)
212
+
213
+ previous_answer = history[-1][1]
214
+ previous_answer = previous_answer if previous_answer is not None else ""
215
+ answer_yet = previous_answer + answer_lst[0]
216
+ answer_yet = parse_output_llm_with_sources(answer_yet)
217
+ history[-1] = (query,answer_yet)
218
+
219
+ history = [tuple(x) for x in history]
220
 
221
+ yield history,docs_html
 
 
 
 
 
 
 
 
 
 
222
  #process_pdf()
223
 
224