lindsay-qu commited on
Commit
2123fe3
·
1 Parent(s): 07eab47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -20,21 +20,29 @@ def chatbot_initialize():
20
  Chatbot = core.chatbot.RetrievalChatbot(retriever=retriever)
21
  return Chatbot
22
 
23
- def respond(query, additional_inputs, image):
24
  global Chatbot
25
- response = Chatbot.response(query, image)
26
- for i in range(len(response)):
27
- time.sleep(0.01)
28
- yield response[: i+1]
 
 
 
29
 
30
  if __name__ == "__main__":
31
  global Chatbot
32
  Chatbot=chatbot_initialize()
33
 
34
- demo = gr.ChatInterface(
35
- fn=respond,
36
- additional_inputs=[
37
- gr.Image(type="filepath"),
38
- ]
39
- )
 
 
 
 
 
40
  demo.queue().launch()
 
20
  Chatbot = core.chatbot.RetrievalChatbot(retriever=retriever)
21
  return Chatbot
22
 
23
+ def respond(query, chat_history, img_path, chat_history_string):
24
  global Chatbot
25
+ response, logs = Chatbot.response(query, image_path=img_path, return_logs=True)
26
+ chat_history.append((query, response))
27
+ if img_path is None:
28
+ chat_history_string += "Query: " + query + "\nImage: None" + "\nRepsonse: " + response + "\n\n\n"
29
+ else:
30
+ chat_history_string += "Query: " + query + "\nImage: " + img_path + "\nRepsonse: " + response + "\n\n\n"
31
+ return "", chat_history, logs, chat_history_string
32
 
33
  if __name__ == "__main__":
34
  global Chatbot
35
  Chatbot=chatbot_initialize()
36
 
37
+ with gr.Blocks() as demo:
38
+ with gr.Row():
39
+ with gr.Column(scale=2):
40
+ chatbot = gr.Chatbot()
41
+ msg = gr.Textbox(label="Query", show_label=True)
42
+ img = gr.Image(type="filepath")
43
+ clear = gr.ClearButton([msg, chatbot])
44
+ with gr.Column(scale=1):
45
+ sidebar = gr.Textbox(label="Subquestions", show_label=True, show_copy_button=True, interactive=False, max_lines=30)
46
+ history = gr.Textbox(label="Copy Chat History", show_label=True, show_copy_button=True, interactive=False, max_lines=5)
47
+ msg.submit(respond, inputs=[msg, chatbot, img, history], outputs=[msg, chatbot, sidebar, history])
48
  demo.queue().launch()