【发布时间】:2020-06-20 17:40:41
【问题描述】:
请让我知道我不包括退货声明的地方。或者是其他地方的问题。我正在使用 Python 3.6 和 Flask。我正在尝试制作一个机器人。该机器人在终端上运行良好。现在我正在尝试给它一个 UI 并使用 Flask。
def chat(user_input):
print("Start talking with the bot !! Press q to quit ")
print("You :"+user_input)
while True:
#inp=input("You: ")
if user_input.lower() == "q":
break
results = model.predict([bag_of_words(user_input, words)])
arr_result = results[0]
print(arr_result)
# gives index of the greatest number
results_index = np.argmax(results)
print('The result_index is '+str(results_index))
# gives the relevant tag
tag = labels[results_index]
print('The tag is ' + tag)
print('labels are'+str(labels))
if arr_result[results_index] > 0.6:
print('arr_result[results_index]>0.6 ' +
str(arr_result[results_index]))
# get a random response from the json file
for tg in data["intents"]:
print(tg)
if tg['tag'] == tag:
response = tg['responses']
print('the array of response is' + str(response))
rand_response = random.choice(response)
bot_response = str(rand_response)
print("Bot: "+bot_response)
return render_template('index.html', user_input=user_input, bot_response=bot_response)
else:
print("Tag not found "+bot_response)
return render_template('index.html', user_input=user_input, bot_response="Sorry, I do not understand")
else:
bot_response = "Sorry, I do not understand"
print("Bot: "+bot_response)
return render_template('index.html', user_input=user_input, bot_response=bot_response)
我不断收到以下错误--
127.0.0.1 - - [08/Mar/2020 02:40:27] "[35m[1mPOST /process HTTP/1.1[0m" 500 -
Traceback (most recent call last):
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
return self.finalize_request(rv)
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1967, in finalize_request
response = self.make_response(rv)
File "C:\Users\Kuldeep\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2097, in make_response
"The view function did not return a valid response. The"
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
127.0.0.1 - - [08/Mar/2020 02:40:27] "[37mGET /process?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Mar/2020 02:40:27] "[37mGET /process?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Mar/2020 02:40:27] "[37mGET /process?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Mar/2020 02:40:27] "[37mGET /process?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Mar/2020 02:40:27] "[37mGET /process?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1[0m" 200 -
【问题讨论】:
标签: python python-3.x flask chatbot