alen commited on
Commit
ed9d94e
·
verified ·
1 Parent(s): d26962d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -23
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
- if not question.files:
137
- local_agent = Agents()
138
- gr.Info("Đang tạo câu trả lời!")
139
- response = ''
140
- output = local_agent.invoke({"question": question.text})
141
- context = output['context']
142
- questions = output['question']
143
- for chunk in generate_chain.stream({"context": context, "question": questions, "chat_history": chat_history}):
144
- response += chunk
145
- print(chunk, end="", flush=True)
146
- yield response
147
-
148
- chat_history.append(HumanMessage(content=question.text))
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
- democ1 = gr.ChatInterface(
159
  QA,
160
  fill_height=True,
161
  multimodal=True,
162
  title="Box Chat(Agent)",
163
- type="tuples"
164
  )
165
 
166
  if __name__ == "__main__":
167
- democ1.launch()
 
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()