Spaces:
Running
Running
Download app.py from Alloire/TouchdownBuddy: direct link, hf CLI and curl.
- Browser
- Download file 917 Bytes
-
https://huggingface.co/spaces/Alloire/TouchdownBuddy/resolve/main/app.py
- Command line
-
hf download hf://spaces/Alloire/TouchdownBuddy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Alloire/TouchdownBuddy/resolve/main/app.py
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) | |