import gradio as gr from TwitterChatBot.main import ask title = "Car Seats Voice Commands" link = "https://cdn.cms-twdigitalassets.com/content/dam/legal-twitter/asset-download-files/TheTwitterUserAgreement_1.pdf" description = f""" # Twitter Terms Of Service ChatBot This chatbot answers questions about **Twitter terms of service** based on this [resource]({link}), The techniques used in this project can be used to answer questions from any kind of business or legal document. ### Examples: try something like - What is twitter? - What actions are permitted for the users? """ def get_answer(question): print(question) answer = ask(question=question) return answer.strip() def predict(input, history=[]): answer = get_answer(input) history.append((input, answer)) response = history return response, history with gr.Blocks() as demo: gr.Markdown(description) chatbot = gr.Chatbot() state = gr.State([]) with gr.Row(): txt = gr.Textbox( show_label=False, placeholder="Ask me a question and press enter" ).style(container=False) txt.submit(predict, [txt, state], [chatbot, state]) demo.launch()