TouchdownBuddy / app.py
Alloire's picture
Update app.py
af2a34a verified
raw
history blame contribute delete
917 Bytes
from transformers import pipeline
import pandas as pd
# Load the dataset
df = pd.read_csv("marksverdhei/wordnet-definitions-en-2021")
# Initialize the question-answering pipeline
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="distilbert-base-cased")
# Function to find the definition of a word
def find_definition(question):
word = question.split(" ")[-1] # Extract the word from the question
definition = df[df['word'] == word]['definition'].values.tolist()
if definition:
return definition[0]
else:
return "Sorry, I couldn't find a definition for that word."
# Main loop for interacting with the chatbot
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Goodbye!")
break
else:
definition = find_definition(user_input)
print("Chatbot:", definition)