【发布时间】:2022-01-09 20:51:52
【问题描述】:
您好,我正在尝试使用 Python 中的 Deeplearning 构建聊天机器人。 (我很新)而且我想要一些命令,比如如果我将“play something”作为输入,机器人应该播放 YouTube 视频。如果“play”不在输入中,它应该从它的深度学习过程中给出答案。但就我而言,它两者兼而有之。有谁知道如何解决它?因此,如果输入中有一个单词,它应该执行一个命令,但如果不是,它应该用深度学习的响应来回答我。所以我的实际问题是我得到两个输出而不是一个。
代码
def chat():
print("Start talking with the bot! (type quit to stop)")
while True:
inp = input("You: ")
# Commands
if inp.lower() == "quit":
break
elif "play" in inp:
song = inp.replace("play", "")
talk("Playing" + song)
print("Playing" + song)
pywhatkit.playonyt(song)
results = model.predict([bag_of_words(inp, words)])[0]
results_index = numpy.argmax(results)
tag = labels[results_index]
if ['play', 'quit'] not in inp:
# If accuracy is over 75% respond with it.
if results[results_index] > 0.75:
for tg in data["intents"]:
if tg['tag'] == tag:
responses = tg['responses']
back = ' ' + random.choice(responses)
talk(back)
print(back)
else:
talk("What are you trying to say?")
print("What are you trying to say?")
chat()
这不是全部代码,我省略了 Deeplearning 和 TTS 部分。 感谢您的帮助!
【问题讨论】:
标签: python python-3.x loops if-statement