'How to embed my python chatbot to a website

I am very new to python, and I am trying to create a chatbot with python for a school project. I am almost done with creating my chatbot, but I don't know how to create a website to display it, I know how to create a website with Flask but how can I embed the chatbot code into the website?



Solution 1:[1]

You would have to create a separate website that talks to the server-hosted chatbot, with messaging between the two (probably using Javascript) to update the site.

A much easier way would be to put your code on Repl.it, and use their repl.run feature that automatically lets users interact with Python code via a website.

Solution 2:[2]

In your flask code you can also embed the chatbot predict-functions into specific routes of your flask app. This would require following steps:

Just before you start the flask server you train the chatbot to ensure its predict function works propperly.

After that you can specifiy some more route-functions to your flask app.

In those functions you grab input from the user (from for example route parameters), send it through the chatbots predict function and then send the respons (probably with postprocessing if you wish) back to the requester.

Sending to the requester can be done through many different ways. Two examples just of my head would be via display (render_template) to the webpage (if the request came in over GET-Request via usual browser site-opening request) or by sending a request to the users ip itself. As a first hand experience i coupled the later mechanism to a telegram bot on my home-automation via post-request which itself then sends the response to me via telegram.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luke Storry
Solution 2 4lexKidd