text_html_output_1.png
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics.pairwise import cosine_similarity

import numpy as np

import pandas as pd

df = pd.read_csv('../input/covidqa/community.csv')

vectorizer = TfidfVectorizer()
vectorizer.fit(np.concatenate((df.question, df.answer)))

Question_vectors = vectorizer.transform(df.question)

name = input('Enter your name : ')
print(f'BOT : Hello {name}! How can I help you ?')
while True:
    input_question = input(f'{name} : ')
    if input_question.lower() == 'bye':
        print(f'BOT : Bye! Have a nice day and maintain proper norms and regulations to stop the spread of COVID.')
        break
    input_question_vector = vectorizer.transform([input_question])
    similarities = cosine_similarity(input_question_vector, Question_vectors)
    closest = np.argmax(similarities, axis=1)
    print(f'BOT : {df.answer.iloc[closest].values[0]}')