Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
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 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
-
|
| 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 |
|