import spacy import random
Load the Spacy English language model
nlp = spacy.load('en_core_web_md')
List of pre-defined responses
responses = [ "I'm sorry, I don't understand what you're trying to say.", "Could you please provide more information?", "I'm sorry, I'm not able to help with that.", "Can you please rephrase that?" ]
while True: # Get user input user_input = input("User: ")
# Parse user input using the Spacy model
doc = nlp(user_input)
# Identify the most similar pre-defined response
best_response = responses[0]
best_similarity = doc.similarity(nlp(responses[0]))
for response in responses:
similarity = doc.similarity(nlp(response))
if similarity > best_similarity:
best_response = response
best_similarity = similarity
# Respond with the most similar pre-defined response
print("Bot: " + best_response)