|
import gradio as gr |
|
from src.ui import UI |
|
from src.chatbot import ChatBot |
|
|
|
def clear_session(): |
|
return "", [] |
|
|
|
def add_query(chat_history, input): |
|
if not input: |
|
raise gr.Error("Please enter a question.") |
|
chat_history.append((input, None)) |
|
return chat_history |
|
|
|
def response(chat_history, query): |
|
res_msg, ref_docs = chatbot.generate_response(query, chat_history[:-1]) |
|
chat_history[-1] = (query, res_msg) |
|
return "", chat_history, ref_docs |
|
|
|
if __name__ == "__main__": |
|
demo, chatspace, ref_docs, text_input, clear_btn = UI.create_demo() |
|
|
|
chatbot = ChatBot(is_debug=True) |
|
with demo: |
|
|
|
text_input.submit(add_query, inputs=[chatspace, text_input], outputs=[chatspace], concurrency_limit=1).\ |
|
success(response, inputs=[chatspace, text_input], outputs=[text_input, chatspace, ref_docs]) |
|
clear_btn.click(clear_session, inputs=[], outputs=[text_input, chatspace]) |
|
|
|
demo.queue(api_open=False) |
|
demo.launch() |
|
|