william4416 commited on
Commit
54a06b3
1 Parent(s): 5179ce7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -34
app.py CHANGED
@@ -12,6 +12,28 @@ qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distil
12
  tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
13
  model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # Function to generate response using dialog generation model
16
  def generate_dialog_response(user_input):
17
  input_text = user_input + tokenizer.eos_token
@@ -23,39 +45,5 @@ def generate_dialog_response(user_input):
23
 
24
  return response_text
25
 
26
- # Function to interactively retrieve user input
27
- def get_user_input():
28
- while True:
29
- try:
30
- # Print prompt and retrieve user input
31
- return input("You: ")
32
- except EOFError:
33
- # If EOFError occurs (e.g., Ctrl+D for EOF on Unix-like systems), inform the user and prompt again
34
- print("\nBot: EOFError occurred. Please provide input.")
35
-
36
- # Main function to interact with the user
37
- def main():
38
- print("Welcome! I'm the UTS Course Chatbot. How can I assist you today?")
39
- print("You can ask questions about UTS courses or type 'exit' to end the conversation.")
40
-
41
- try:
42
- while True:
43
- user_input = get_user_input()
44
- if user_input.lower() == 'exit':
45
- print("Bot: Exiting the program.")
46
- break
47
- elif "courses" in user_input.lower() and "available" in user_input.lower():
48
- field = user_input.split("in ")[1]
49
- courses = data['courses'].get(field, [])
50
- if courses:
51
- response = f"Courses in {field}: {', '.join(courses)}"
52
- else:
53
- response = f"No courses found in {field}."
54
- else:
55
- response = generate_dialog_response(user_input)
56
- print("Bot:", response)
57
- except KeyboardInterrupt:
58
- print("\nBot: Exiting the program.")
59
-
60
  if __name__ == "__main__":
61
  main()
 
12
  tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
13
  model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
14
 
15
+ # Main function to interact with the user
16
+ def main():
17
+ print("Welcome! I'm the UTS Course Chatbot. How can I assist you today?")
18
+ print("You can ask questions about UTS courses or type 'exit' to end the conversation.")
19
+
20
+ while True:
21
+ user_input = input("You: ")
22
+ if user_input.lower() == 'exit':
23
+ print("Bot: Exiting the program.")
24
+ break
25
+
26
+ if "courses" in user_input.lower() and "available" in user_input.lower():
27
+ field = user_input.split("in ")[-1]
28
+ courses = data['courses'].get(field, [])
29
+ if courses:
30
+ response = f"Courses in {field}: {', '.join(courses)}"
31
+ else:
32
+ response = f"No courses found in {field}."
33
+ else:
34
+ response = generate_dialog_response(user_input)
35
+ print("Bot:", response)
36
+
37
  # Function to generate response using dialog generation model
38
  def generate_dialog_response(user_input):
39
  input_text = user_input + tokenizer.eos_token
 
45
 
46
  return response_text
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  if __name__ == "__main__":
49
  main()