Основной Python Chatbot
- Цель задачи - создать чат-бота Basic Python, в котором на любые вопросы, задаваемые, если чат-бот не знает ответа, отображается запрос пользователя на предоставление ответов. Как только ответ получен, он должен записать этот вопрос и ответить на него в кадре данных pandas. В будущем задается аналогичный вопрос, чатбот должен посмотреть в фрейм данных панд и дать ответ.
- Цель создания фрейма данных pandas заключается в том, что в настоящее время у меня нет готовых вопросов и ответов, поэтому со временем я буду добавлять вопрос и ответ в фрейм данных pandas один за другим.
Blockquote
username = "User"
chatbotname = "<>"
chatbotnameknown = False
active = True
def saychatbot(text):
global username
global chatbotname
global chatbotnameknown
global active
if chatbotnameknown:
print(chatbotname + ": " + text)
else:
print("*: " + text)
def speak(user_entry):
global username
global chatbotname
global chatbotnameknown
global active
if user_entry == "Hello!" or user_entry == "hello":
saychatbot("Hi, " + username)
elif user_entry == "How are you?":
saychatbot("I'm fine. And you?")
reply = input("Your answer: ")
if reply == "Great":
saychatbot("I'm glad to hear that.")
else:
saychatbot("I didn't understand you.")
elif user_entry == "Bye":
active = False
else:
saychatbot("I didn't understand you.")
saychatbot("I am still learning, let me learn your language")
if input("Would you like to teach me your language, Say y/n ? ") == "y":
saychatbot("You know i am still infancy, so please teach me your language one question and its answer at a time so i will load it in my database!!")
print("Here I would like to record the question and its answer in Pandas data frame and use that data frame as input to answer the same question in future")
print("Is there any way to achieve it")
def OpenDiscussion():
global username
global chatbotname
global chatbotnameknown
global active
print("********Python - Do you know system can speak****************")
while active:
if chatbotnameknown:
speak(str(input(username + ": " + chatbotname + ", ")))
else:
speak(str(input(username + ": ")))
saychatbot("Bye.")
OpenDiscussion()