Spaces:
Build error
Build error
alen commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,35 +133,27 @@ def Agents():
|
|
| 133 |
|
| 134 |
def QA(question: str, history: list):
|
| 135 |
# print(question.text, question.files, history, type)
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
chat_history.append(AIMessage(content=response))
|
| 150 |
-
|
| 151 |
-
else:
|
| 152 |
-
print(question.files)
|
| 153 |
-
# all_loaders = []
|
| 154 |
-
# for pdf in question.files:
|
| 155 |
-
# pdf_loader = PyPDFLoader("data/Đắc Nhân Tâm.pdf")
|
| 156 |
|
| 157 |
|
| 158 |
-
|
| 159 |
QA,
|
| 160 |
fill_height=True,
|
| 161 |
multimodal=True,
|
| 162 |
title="Box Chat(Agent)",
|
| 163 |
-
type="tuples"
|
| 164 |
)
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
-
|
|
|
|
| 133 |
|
| 134 |
def QA(question: str, history: list):
|
| 135 |
# print(question.text, question.files, history, type)
|
| 136 |
+
local_agent = Agents()
|
| 137 |
+
gr.Info("Đang tạo câu trả lời!")
|
| 138 |
+
response = ''
|
| 139 |
+
output = local_agent.invoke({"question": question})
|
| 140 |
+
context = output['context']
|
| 141 |
+
questions = output['question']
|
| 142 |
+
for chunk in generate_chain.stream({"context": context, "question": questions, "chat_history": chat_history}):
|
| 143 |
+
response += chunk
|
| 144 |
+
print(chunk, end="", flush=True)
|
| 145 |
+
yield response
|
| 146 |
+
|
| 147 |
+
chat_history.append(HumanMessage(content=question))
|
| 148 |
+
chat_history.append(AIMessage(content=response))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
+
demo = gr.ChatInterface(
|
| 152 |
QA,
|
| 153 |
fill_height=True,
|
| 154 |
multimodal=True,
|
| 155 |
title="Box Chat(Agent)",
|
|
|
|
| 156 |
)
|
| 157 |
|
| 158 |
if __name__ == "__main__":
|
| 159 |
+
demo.launch()
|