Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,50 +4,45 @@ from huggingface_hub import hf_hub_download
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
# ==========================================
|
| 7 |
-
# 1. THE "
|
| 8 |
# ==========================================
|
| 9 |
-
#
|
| 10 |
-
#
|
|
|
|
| 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 |
-
"
|
| 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**, **
|
| 48 |
|
| 49 |
# ==========================================
|
| 50 |
-
# 2. MODEL SETUP (
|
| 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 (
|
| 67 |
# ==========================================
|
| 68 |
def chat_with_bot(message, history):
|
| 69 |
-
#
|
| 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.
|
| 78 |
-
#
|
|
|
|
| 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
|
| 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:
|
| 116 |
examples=[
|
| 117 |
-
"
|
| 118 |
-
"Who is the
|
| 119 |
-
"What is the
|
| 120 |
-
"
|
| 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 |
)
|