| ## chatbot app | |
| import requests | |
| import gradio as gr | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox() | |
| clear = gr.Button('clear') | |
| def response(user_query , history): | |
| url = f"https://text.pollinations.ai/{user_query}" | |
| res = requests.get(url) | |
| bot_reply = res.content.decode('utf-8') | |
| history = history + [(user_query , bot_reply)] | |
| return history , history | |
| msg.submit(response , [msg,chatbot] , [chatbot,chatbot]) | |
| clear.click(lambda:[] , None , chatbot , queue=False) | |
| demo.launch(share=True) |