我是 Python 开发的新手。我正在尝试将ChatterBot集成到本地主机上的网页中。所以要做到这一点,我的第一个挑战是在网页和 Python 脚本之间建立对话,我已经实现了这一点。我面临的问题是 - 当我使用列表训练 ChatterBot 时,它会显示详细信息,但我不希望网页上出现这些详细信息,因为它们对最终用户没有用,所以为此我尝试了不同的logging.basicConfig - 2 个日志记录级别,但我无法隐藏日志。
这是我的网页(index.html):
<!DOCTYPE html>
<html>
<body>
<h2>Text Input</h2>
<form action = "chatbot.py" method = "POST" >
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<button type = "submit" >Submit</button>
</form>
<p>Note that the form itself is not visible.</p>
<p>Also note that the default width of a text input field is 20 characters.</p>
</body>
</html>
这是chatbot.py
#!C:\Users\Shishupal\AppData\Local\Programs\Python\Python36-32\python.exe
# This program prints Hello, world!
from chatterbot import ChatBot
import logging
print("Content-Type: text/html")
print()
import cgi
print('Hello, world!')
logging.basicConfig(logging.INFO)
# Create a new chat bot named Charlie
chatbot = ChatBot(
'Charlie',
trainer='chatterbot.trainers.ListTrainer'
)
chatbot.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'How are you?'
response = chatbot.get_response('I would like to book a flight.')
print(response)
当我不输入或将 logging.basicConfig(logging.INFO) 放入 chatbot.py 时会出现冗长,因此我想隐藏这些日志,因为它们对最终用户没有用处。
全球有没有 Python 专家可以帮我解决这个问题:)