Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to make Intelligent chat Robot with Python

Shulou Source: shulou.com Published: 2022-06-01 04:07:30 09月16日 Update

This article introduces the relevant knowledge of "how to make intelligent chat robots with Python". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

[The effect is as follows]

[Implementation process]

1. GUI interface production, not much to say.

2. Implementation of intelligent chat robot:

Therefore, I applied for an account (unauthenticated individual users can only reply 3 times/day, and 100 times/day can be realized after authentication; of course, there are more RMB players).

After applying for an account, it is very simple. Send http request through post request, and the response is the reply of Turing robot. The only thing to note is that in the content of the Post request body, key is the apikey value applied by yourself;usrid can be set at will, info is the question entered by the user, as shown in the following figure:

[Sample Code]

# coding= utf-8#@Auther: "Peng Ge Thief Excellent"# @Date : 2019/8/16#@Software: PyCharm

from PyQt5 import QtCore, QtGui, QtWidgetsimport sysimport requests

class Ui_Dialog(object): def setupUi(self, Dialog): Dialog.setObjectName("Smart Chatbot") Dialog.resize(582, 434) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(40, 30, 361, 51)) self.label.setStyleSheet("color: rgb(0, 0, 255);\n""font: 16pt \" black body\";\n""text-decoration: underline;") self.label.setObjectName("dialog") self.plainTextEdit = QtWidgets.QPlainTextEdit(Dialog) self.plainTextEdit.setGeometry(QtCore.QRect(40, 80, 501, 181)) self.plainTextEdit.setObjectName("plainTextEdit") self.plainTextEdit_2 = QtWidgets.QPlainTextEdit(Dialog) self.plainTextEdit_2.setGeometry(QtCore.QRect(40, 310, 401, 41)) self.plainTextEdit_2.setObjectName("plainTextEdit_2") self.plainTextEdit.setStyleSheet("font: 14pt\" Bold\";\n") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(480, 320, 75, 23)) self.pushButton.setStyleSheet("font: 14pt \" black body\";\n""background-color: rgb(0, 255, 0);") self.pushButton.setObjectName("pushButton") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(50, 280, 54, 12)) self.label_2.setText("") self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(50, 280, 71, 16)) self.label_3.setStyleSheet("font: 75 12pt \"Aharoni\";") self.label_3.setObjectName("label_3")

self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Smart Chatbot")) self.label.setText(_translate("Dialog", "Welcome to Turing Intelligent Chatbot: ")) self.pushButton.setText(_translate("Dialog", "Send")) self.label_3.setText(_translate("Dialog", "Input Box")) self.pushButton.clicked.connect(self.get_response)

def get_response(self): enterstr = self.plainTextEdit_2.toPlainText() url = 'http://www.tuling123.com/openapi/api' data = { 'key':' own key', 'info': enterstr, 'userid': "test", } r = requests.post(url, data=data).json() result = ">> Me: {0}\n \n>> Xiaoqi: {1}#^_^# \n".format(enterstr,r.get("text")) self.plainTextEdit.setPlainText(result) return result

if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) main = QtWidgets.QMainWindow() mainwindow = Ui_Dialog() mainwindow.setupUi(main) main.show() sys.exit(app.exec())"How to use Python to make intelligent chatbots" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Machines robots intelligence production content more boldface Turing users knowledge accounts processes authentication input excellence practicality learning and then individuals people Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info MySQL Shulou Information MariaDB