LovnishVerma commited on
Commit
5a14d45
Β·
verified Β·
1 Parent(s): d33966e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -37
app.py CHANGED
@@ -4,50 +4,45 @@ from huggingface_hub import hf_hub_download
4
  import os
5
 
6
  # ==========================================
7
- # 1. THE "CHEAT SHEET" (Hardcoded Accuracy)
8
  # ==========================================
9
- # I have added EVERY key role here. It matches keywords in your question
10
- # to the perfect answer.
 
11
  KNOWLEDGE_TRIGGERS = {
12
- # --- LEADERSHIP ---
 
 
13
  "head of training": "πŸŽ“ **Head of Training (HoD):**\nMrs. Anita Budhiraja (Scientist 'E')",
14
  "hod": "πŸŽ“ **Head of Training (HoD):**\nMrs. Anita Budhiraja (Scientist 'E')",
15
- "anita": "πŸŽ“ **Head of Training (HoD):**\nMrs. Anita Budhiraja (Scientist 'E')",
16
-
17
  "vc": "πŸ›οΈ **Vice Chancellor:**\nDr. Madan Mohan Tripathi",
18
  "vice chancellor": "πŸ›οΈ **Vice Chancellor:**\nDr. Madan Mohan Tripathi",
19
- "tripathi": "πŸ›οΈ **Vice Chancellor:**\nDr. Madan Mohan Tripathi",
20
-
21
  "registrar": "πŸ“œ **Registrar:**\nDr. Manish Arora (Scientist 'F')",
22
- "manish": "πŸ“œ **Registrar:**\nDr. Manish Arora (Scientist 'F')",
23
-
24
  "executive director": "🏒 **Executive Director:**\nMr. Deepak Wasan",
25
- "ed": "🏒 **Executive Director:**\nMr. Deepak Wasan",
26
- "director": "🏒 **Executive Director:**\nMr. Deepak Wasan",
27
-
28
- # --- FACULTY ---
29
- "faculty": "πŸ‘¨β€πŸ« **Key Faculty Members:**\n- **Dr. Sarwan Singh** (Scientist 'D')\n- **Dr. Muneer Ahmad Dar** (Scientist 'D')\n- **Ms. Sonia Bansal** (Scientist 'E')\n- **Sh. Raminder Singh** (Scientist 'E')",
30
- "professor": "πŸ‘¨β€πŸ« **Key Faculty Members:**\n- **Dr. Sarwan Singh** (Scientist 'D')\n- **Dr. Muneer Ahmad Dar** (Scientist 'D')",
31
- "sarwan": "πŸ‘¨β€πŸ« **Dr. Sarwan Singh** is a Scientist 'D' and member of the Academic Council.",
32
 
33
  # --- FEES & ADMISSIONS ---
34
  "fee": "πŸ’° **Fee Structure (Per Semester):**\n- **B.Tech:** Rs. 50,000\n- **M.Tech:** Rs. 60,000\n- **BCA:** Rs. 30,000\n- **Hostel:** Rs. 1,600/mo",
35
  "cost": "πŸ’° **Fee Structure (Per Semester):**\n- **B.Tech:** Rs. 50,000\n- **M.Tech:** Rs. 60,000\n- **BCA:** Rs. 30,000",
36
  "admission": "πŸ“ **Admissions 2025-26:**\n- **B.Tech:** JEE Mains / Institute Exam\n- **M.Tech:** GATE / Institute Exam\n- **Exam Date:** June 12, 2025",
37
- "dates": "πŸ“… **Important Dates:**\n- **Classes Start:** Aug 25, 2025\n- **Mid-Sem Exams:** Oct 27, 2025",
38
-
 
 
 
 
 
 
 
39
  # --- INFRASTRUCTURE ---
40
  "hostel": "🏨 **Hostel:**\n- Separate Boys/Girls hostels.\n- **Rent:** Rs. 1,600/month.\n- **Mess:** ~Rs. 4,500/month.\n- Wi-Fi & Gym included.",
41
- "mess": "🍽️ **Mess:**\n- Healthy meals 4 times a day.\n- Charges: Approx Rs. 4,500 per month.",
42
- "lab": "πŸ’» **Labs:**\n- AI/ML Lab with GPU Servers\n- IoT & Smart Sensors Lab\n- Cyber Forensics Lab\n- SMART Lab (VLSI)",
43
  "placement": "πŸ’Ό **Placements:**\n- **Highest:** Rs. 18 LPA\n- **Average:** Rs. 4.5 LPA\n- **Top Recruiters:** Intel, Dell, Wipro, Infosys"
44
  }
45
 
46
  GREETINGS_LIST = ["hi", "hello", "hey", "hlo", "greetings", "good morning", "start", "yo"]
47
- WELCOME_MESSAGE = "Hello! I am the NIELIT Ropar Assistant. Ask me about **Admissions**, **Fees**, **Head of Training**, or **Faculty**."
48
 
49
  # ==========================================
50
- # 2. MODEL SETUP (Your Trained Model)
51
  # ==========================================
52
  MODEL_REPO = "LovnishVerma/nielit-ropar-ndu-GGUF"
53
  MODEL_FILE = "nielit-ropar-ndu.q4_k_m.gguf"
@@ -61,27 +56,29 @@ try:
61
  print("βœ… Inference Engine Ready")
62
  except Exception as e:
63
  print(f"⚠️ Model Load Error: {e}")
 
64
 
65
  # ==========================================
66
- # 3. CHAT LOGIC (The "Cannot Fail" Logic)
67
  # ==========================================
68
  def chat_with_bot(message, history):
69
- # Clean input: remove punctuation, make lowercase
70
- msg_clean = message.lower().strip().replace("?", "").replace(".", "")
71
 
72
  # 1. Check Greetings
73
- if msg_clean in GREETINGS_LIST:
74
  yield WELCOME_MESSAGE
75
  return
76
 
77
- # 2. Check Cheat Sheet (Iterate through all triggers)
78
- # This loop ensures "Who is the Head of Training?" catches the "head of training" key
 
79
  for keyword, answer in KNOWLEDGE_TRIGGERS.items():
80
  if keyword in msg_clean:
81
  yield answer
82
  return
83
 
84
- # 3. Fallback to AI (Only for unknown questions)
85
  if llm:
86
  prompt = f"### Instruction:\nYou are the NIELIT Ropar Assistant. Answer strictly.\n\n### User Question:\n{message}\n\n### Response:\n"
87
  try:
@@ -94,12 +91,11 @@ def chat_with_bot(message, history):
94
  except Exception:
95
  yield "Please check the official website at nielit.ac.in/ropar."
96
  else:
97
- yield "System Offline."
98
 
99
  # ==========================================
100
  # 4. UI SETUP
101
  # ==========================================
102
- # Check for bot.png
103
  current_dir = os.path.dirname(os.path.abspath(__file__))
104
  local_image = os.path.join(current_dir, "bot.png")
105
  avatar = local_image if os.path.exists(local_image) else "https://cdn-icons-png.flaticon.com/512/4712/4712027.png"
@@ -112,12 +108,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
112
  gr.ChatInterface(
113
  fn=chat_with_bot,
114
  chatbot=gr.Chatbot(height=500, show_label=False, avatar_images=(None, avatar)),
115
- textbox=gr.Textbox(placeholder="Ask: Who is Head of Training? or What is the Fee?", container=False, scale=7),
116
  examples=[
117
- "Who is the Head of Training?",
118
- "Who is the Vice Chancellor?",
119
- "What is the B.Tech Fee?",
120
- "Tell me about Placements"
121
  ],
122
  cache_examples=False,
123
  )
 
4
  import os
5
 
6
  # ==========================================
7
+ # 1. THE "GOD MODE" DICTIONARY (Hardcoded Truth)
8
  # ==========================================
9
+ # This dictionary intercepts the user input.
10
+ # If the user types ANY of these keywords, the model is SILENCED
11
+ # and this exact text is returned.
12
  KNOWLEDGE_TRIGGERS = {
13
+ # --- LEADERSHIP & FACULTY ---
14
+ "faculty": "πŸ‘¨β€πŸ« **Key Faculty Members:**\n- **Dr. Sarwan Singh** (Scientist 'D')\n- **Dr. Muneer Ahmad Dar** (Scientist 'D')\n- **Ms. Sonia Bansal** (Scientist 'E')\n- **Sh. Raminder Singh** (Scientist 'E')",
15
+ "professors": "πŸ‘¨β€πŸ« **Key Faculty Members:**\n- **Dr. Sarwan Singh** (Scientist 'D')\n- **Dr. Muneer Ahmad Dar** (Scientist 'D')",
16
  "head of training": "πŸŽ“ **Head of Training (HoD):**\nMrs. Anita Budhiraja (Scientist 'E')",
17
  "hod": "πŸŽ“ **Head of Training (HoD):**\nMrs. Anita Budhiraja (Scientist 'E')",
 
 
18
  "vc": "πŸ›οΈ **Vice Chancellor:**\nDr. Madan Mohan Tripathi",
19
  "vice chancellor": "πŸ›οΈ **Vice Chancellor:**\nDr. Madan Mohan Tripathi",
 
 
20
  "registrar": "πŸ“œ **Registrar:**\nDr. Manish Arora (Scientist 'F')",
 
 
21
  "executive director": "🏒 **Executive Director:**\nMr. Deepak Wasan",
 
 
 
 
 
 
 
22
 
23
  # --- FEES & ADMISSIONS ---
24
  "fee": "πŸ’° **Fee Structure (Per Semester):**\n- **B.Tech:** Rs. 50,000\n- **M.Tech:** Rs. 60,000\n- **BCA:** Rs. 30,000\n- **Hostel:** Rs. 1,600/mo",
25
  "cost": "πŸ’° **Fee Structure (Per Semester):**\n- **B.Tech:** Rs. 50,000\n- **M.Tech:** Rs. 60,000\n- **BCA:** Rs. 30,000",
26
  "admission": "πŸ“ **Admissions 2025-26:**\n- **B.Tech:** JEE Mains / Institute Exam\n- **M.Tech:** GATE / Institute Exam\n- **Exam Date:** June 12, 2025",
27
+ "why join": "🌟 **Why Join NIELIT Ropar?**\n- **Govt. of India Institute** (under MeitY).\n- **Adjacent to IIT Ropar** (Academic Collaboration).\n- **SMART Labs** with GPU Servers & VLSI Tools.\n- **Excellent Placements** (Highest: 18 LPA).",
28
+ "benefit": "🌟 **Why Join NIELIT Ropar?**\n- **Govt. of India Institute** (under MeitY).\n- **Adjacent to IIT Ropar** (Academic Collaboration).\n- **SMART Labs** with GPU Servers & VLSI Tools.\n- **Excellent Placements** (Highest: 18 LPA).",
29
+
30
+ # --- LOCATION ---
31
+ "located": "πŸ“ **Address:**\nNIELIT Ropar, Birla Farms, Bada Phull, Rupnagar (Ropar) - 140001.\n(Adjacent to IIT Ropar New Campus).",
32
+ "location": "πŸ“ **Address:**\nNIELIT Ropar, Birla Farms, Bada Phull, Rupnagar (Ropar) - 140001.",
33
+ "where": "πŸ“ **Address:**\nNIELIT Ropar, Birla Farms, Bada Phull, Rupnagar (Ropar) - 140001.",
34
+ "campus": "πŸ“ **Campus Location:**\nBirla Farms, Bada Phull, Rupnagar (Ropar) - 140001.",
35
+
36
  # --- INFRASTRUCTURE ---
37
  "hostel": "🏨 **Hostel:**\n- Separate Boys/Girls hostels.\n- **Rent:** Rs. 1,600/month.\n- **Mess:** ~Rs. 4,500/month.\n- Wi-Fi & Gym included.",
 
 
38
  "placement": "πŸ’Ό **Placements:**\n- **Highest:** Rs. 18 LPA\n- **Average:** Rs. 4.5 LPA\n- **Top Recruiters:** Intel, Dell, Wipro, Infosys"
39
  }
40
 
41
  GREETINGS_LIST = ["hi", "hello", "hey", "hlo", "greetings", "good morning", "start", "yo"]
42
+ WELCOME_MESSAGE = "Hello! I am the NIELIT Ropar Assistant. Ask me about **Admissions**, **Fees**, **Why Join?**, or **Faculty**."
43
 
44
  # ==========================================
45
+ # 2. MODEL SETUP (Fallback Only)
46
  # ==========================================
47
  MODEL_REPO = "LovnishVerma/nielit-ropar-ndu-GGUF"
48
  MODEL_FILE = "nielit-ropar-ndu.q4_k_m.gguf"
 
56
  print("βœ… Inference Engine Ready")
57
  except Exception as e:
58
  print(f"⚠️ Model Load Error: {e}")
59
+ print("⚠️ RUNNING IN 'GOD MODE' ONLY (Dictionary Rules Active)")
60
 
61
  # ==========================================
62
+ # 3. CHAT LOGIC (Dictator Logic)
63
  # ==========================================
64
  def chat_with_bot(message, history):
65
+ # Aggressive cleaning: Lowercase, remove special chars
66
+ msg_clean = message.lower().strip().replace("?", "").replace(".", "").replace("!", "")
67
 
68
  # 1. Check Greetings
69
+ if any(g in msg_clean for g in GREETINGS_LIST):
70
  yield WELCOME_MESSAGE
71
  return
72
 
73
+ # 2. DICTATOR CHECK (The Fix)
74
+ # We iterate through the dictionary. If ANY keyword matches, we return the fact.
75
+ # This prevents the "Labs" hallucination for "Faculty" queries.
76
  for keyword, answer in KNOWLEDGE_TRIGGERS.items():
77
  if keyword in msg_clean:
78
  yield answer
79
  return
80
 
81
+ # 3. Fallback to AI (Only if NO keywords matched)
82
  if llm:
83
  prompt = f"### Instruction:\nYou are the NIELIT Ropar Assistant. Answer strictly.\n\n### User Question:\n{message}\n\n### Response:\n"
84
  try:
 
91
  except Exception:
92
  yield "Please check the official website at nielit.ac.in/ropar."
93
  else:
94
+ yield "System Offline. Please check nielit.ac.in."
95
 
96
  # ==========================================
97
  # 4. UI SETUP
98
  # ==========================================
 
99
  current_dir = os.path.dirname(os.path.abspath(__file__))
100
  local_image = os.path.join(current_dir, "bot.png")
101
  avatar = local_image if os.path.exists(local_image) else "https://cdn-icons-png.flaticon.com/512/4712/4712027.png"
 
108
  gr.ChatInterface(
109
  fn=chat_with_bot,
110
  chatbot=gr.Chatbot(height=500, show_label=False, avatar_images=(None, avatar)),
111
+ textbox=gr.Textbox(placeholder="Ask: Why should I join? or Who is the Faculty?", container=False, scale=7),
112
  examples=[
113
+ "Why should I join NIELIT?",
114
+ "Who is the Faculty?",
115
+ "What is the Fee?",
116
+ "Where is it located?"
117
  ],
118
  cache_examples=False,
119
  )