-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv1.py
More file actions
77 lines (58 loc) · 2.52 KB
/
v1.py
File metadata and controls
77 lines (58 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import tkinter as tk
from tkinter import scrolledtext
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
import spacy
import os
import sys
nlp = spacy.load("en_core_web_sm")
# keyworrds
faq_responses = {
"admission": "Admissions open in July every year. You can apply online through our official website.",
"courses": "We offer B.Tech, BBA, MBA, and MCA programs. Visit our website for more details.",
"schedule": "Class schedules are shared on the student portal every semester.",
"fees": "Fee details vary by course. You can find them in the Admissions > Fee Structure section online.",
"contact": "You can reach us at contact@college.edu or call 1800-123-456.",
"hostel": "Yes, we provide separate hostel facilities for boys and girls.",
"placement": "Our top recruiters include Infosys, TCS, and Wipro with an average package of 6 LPA.",
}
# preprocessing text
def preprocess(text):
text = text.lower()
words = word_tokenize(text)
filtered = [w for w in words if w.isalnum() and w not in stopwords.words('english')]
return filtered
# bot response
def get_response(user_input):
keywords = preprocess(user_input)
doc = nlp(user_input.lower())
for keyword in faq_responses:
if keyword in keywords or keyword in [token.lemma_ for token in doc]:
return faq_responses[keyword]
return "I'm sorry, I don't have information on that. Please contact the admin office for help."
# gui function
def send_message():
user_input = user_entry.get()
if not user_input.strip():
return
chat_box.insert(tk.END, "You: " + user_input + "\n", "user")
response = get_response(user_input)
chat_box.insert(tk.END, "Bot: " + response + "\n\n", "bot")
user_entry.delete(0, tk.END)
# tkinter setup
root = tk.Tk()
root.title("College Query Chatbot")
root.geometry("500x550")
root.resizable(False, False)
chat_box = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=60, height=25, font=("Arial", 10))
chat_box.pack(padx=10, pady=10)
chat_box.tag_config("user", foreground="blue")
chat_box.tag_config("bot", foreground="green")
user_entry = tk.Entry(root, width=45, font=("Arial", 12))
user_entry.pack(side=tk.LEFT, padx=10, pady=10)
send_button = tk.Button(root, text="Send", command=send_message, bg="#4CAF50", fg="white", font=("Arial", 10, "bold"))
send_button.pack(side=tk.LEFT, padx=5, pady=10)
chat_box.insert(tk.END, "Bot: Hello! I’m your college assistant. How can I help you today?\n\n", "bot")
#mainloop
root.mainloop()