| import gradio as gr | |
| from rag import respond_rag_huggingface as response_hf | |
| chat_history = [] | |
| def respond(message): | |
| global chat_history | |
| response = response_hf(message) | |
| chat_history.append((message, response)) | |
| return "", chat_history | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Game of Thrones Q&A bot") | |
| chatbot = gr.Chatbot(label="Chat History") | |
| msg = gr.Textbox(label="Write something about Game of Thrones here...") | |
| clear = gr.Button("Clear") | |
| msg.submit(respond, inputs=[msg], outputs=[msg, chatbot]) | |
| clear.click(lambda: ([], ""), None, [chatbot, msg]) | |
| demo.launch() | |