-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py (7)
More file actions
47 lines (38 loc) · 2.4 KB
/
main.py (7)
File metadata and controls
47 lines (38 loc) · 2.4 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
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# ১. নলেজবেস তৈরি (Knowledge Base)
# এখানে আপনি আপনার অফিসের ম্যানুয়াল বা যেকোনো বড় টেক্সট রাখতে পারেন
knowledge_base = [
"Our office hours are from 9:00 AM to 6:00 PM, Sunday to Thursday.",
"Employees are entitled to 20 days of paid leave per year.",
"The IT support desk is located on the 4th floor for hardware issues.",
"Parking is free for employees in the basement level B1 and B2.",
"Submit your expense reports by the 5th of every month.",
"The office cafeteria provides lunch from 1:00 PM to 2:00 PM."
]
# ২. NLP মডেল ও ভেক্টরাইজেশন (Text Embedding)
vectorizer = TfidfVectorizer()
# পুরো নলেজবেসকে সংখ্যায় (Vectors) রূপান্তর করা হচ্ছে
knowledge_vectors = vectorizer.fit_transform(knowledge_base)
def smart_librarian_bot(user_query):
# ইউজারের প্রশ্নকেও সংখ্যায় রূপান্তর করা
query_vector = vectorizer.transform([user_query])
# ৩. সার্চ ফাংশনালিটি (Cosine Similarity ব্যবহার করে মিল খোঁজা)
similarities = cosine_similarity(query_vector, knowledge_vectors)
# সবচেয়ে বেশি মিল থাকা উত্তরের ইনডেক্স বের করা
best_match_index = np.argmax(similarities)
max_similarity = similarities[0][best_match_index]
# কনফিডেন্স চেক (০.২ এর নিচে মিল হলে সে বলবে জানি না)
if max_similarity < 0.2:
return "Bot: I'm sorry, I couldn't find relevant information in the manual."
return f"Bot: {knowledge_base[best_match_index]} (Confidence: {max_similarity:.2f})"
# ৪. ইন্টারঅ্যাক্টিভ লুপ
print("--- Advanced NLP Chatbot (Manual Assistant) ---")
print("Ask me anything from the office manual (Type 'exit' to quit)")
while True:
user_input = input("\nYou: ")
if user_input.lower() == 'exit':
break
print(smart_librarian_bot(user_input))