Alloire commited on
Commit
0ff9065
·
verified ·
1 Parent(s): dff78a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,22 +1,28 @@
1
- import streamlit as st
2
  from datasets import load_dataset
3
 
4
  # Load the dataset
5
  dataset = load_dataset("marksverdhei/wordnet-definitions-en-2021")
6
 
7
- # Streamlit app
8
- st.title("TouchDown Buddy Chatbot")
9
-
10
- # Input question
11
- question = st.text_input("Enter your question:")
12
-
13
- # Search for the corresponding definition
14
- if question:
15
  found = False
16
  for example in dataset["train"]:
17
- if question.lower() in example["word"].lower():
18
- st.write("Definition:", example["gloss"])
19
  found = True
20
  break
21
  if not found:
22
- st.write("Sorry, the answer to your question is not available.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from datasets import load_dataset
2
 
3
  # Load the dataset
4
  dataset = load_dataset("marksverdhei/wordnet-definitions-en-2021")
5
 
6
+ def get_definition(word):
 
 
 
 
 
 
 
7
  found = False
8
  for example in dataset["train"]:
9
+ if word.lower() in example["word"].lower():
10
+ return example["gloss"]
11
  found = True
12
  break
13
  if not found:
14
+ return "Sorry, the definition for '{}' is not available.".format(word)
15
+
16
+ def main():
17
+ while True:
18
+ user_input = input("Enter your question (or type 'quit' to exit): ")
19
+ if user_input.lower() == "quit":
20
+ print("Goodbye!")
21
+ break
22
+ else:
23
+ word_to_define = user_input.split()[-1] # Get the last word from the user input
24
+ definition = get_definition(word_to_define)
25
+ print("Definition:", definition)
26
+
27
+ if __name__ == "__main__":
28
+ main()