File size: 28,028 Bytes
5b6a879 dfe8c61 5b6a879 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 5b6a879 4d50eee 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 156c2de 6c4e8c0 4d50eee 6c4e8c0 156c2de 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 5b6a879 6c4e8c0 4d50eee 6c4e8c0 5b6a879 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 5b6a879 6c4e8c0 4d50eee 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 4d50eee 6c4e8c0 4d50eee 6c4e8c0 156c2de 6c4e8c0 156c2de 6c4e8c0 5b6a879 6c4e8c0 cbd297e 078e953 a1b6714 078e953 a1b6714 078e953 62dce3c 078e953 62dce3c 078e953 6c4e8c0 078e953 62dce3c 078e953 62dce3c 078e953 62dce3c 078e953 62dce3c 078e953 62dce3c 078e953 16e2d38 6c4e8c0 078e953 6c4e8c0 078e953 |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# BOUESTI Virtual Assistant Chatbot
# Bamidele Olumilua University of Education, Science, and Technology, Ikere Ekiti
import nltk
import re
import random
import string
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
import warnings
import gradio as gr
warnings.filterwarnings('ignore')
# Download required NLTK data
nltk.download('punkt')
nltk.download('punkt_tab')
nltk.download('wordnet')
nltk.download('stopwords')
nltk.download('omw-1.4')
from nltk.stem import WordNetLemmatizer
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
class BOUESTIChatbot:
def __init__(self):
self.lemmatizer = WordNetLemmatizer()
self.stop_words = set(stopwords.words('english'))
self.first_greeting = True
self.user_name = None
self.awaiting_name = False # Flag to indicate if the bot is waiting for a name
# Initialize knowledge base
self.knowledge_base = {
# University Information
'university_info': {
'name': 'Bamidele Olumilua University of Education, Science, and Technology, Ikere Ekiti',
'acronym': 'BOUESTI',
'location': 'Ikere Ekiti, Nigeria',
'contact_email': ['[email protected]', '[email protected]'],
'contact_phone': ['+234-805-797-5157', '+234-814-008-0237', '+234-701-930-3769'],
'website': 'portal.bouesti.edu.ng',
'ranking': 'Listed in World Universities Ranking 2023 (Reporter\'s category)',
'mission': 'To generate, disseminate, advance knowledge, and educate students in science and technology with the aim of bringing this knowledge to finding solutions to the major challenges facing society and the world\'s challenges in the 21st century.',
'vision': 'To be an international University recognized and noted for innovation and self-reliance projecting culturally sound and disciplined researchers and products who are committed to learning for gainful engagement for the proper education of the total man.'
},
# Admission Requirements
'admission_requirements': {
'utme_score': 140,
'olevel_requirements': '5 O\'Level Credit passes including English Language, Mathematics, and 3 other relevant subjects at not more than 2 sittings',
'direct_entry': 'NCE, HND, ND, JUPEB, and IJMB qualifications are acceptable',
'jamb_requirements': 'Must change institution to BOUESTI on JAMB portal and upload WAEC/SSCE results'
},
# Application Process
'application_process': {
'post_utme_steps': [
'Visit portal.bouesti.edu.ng',
'Click on Admissions',
'Click on Apply for Admission',
'Create a new account',
'Supply required details and verify email',
'Login with email and password',
'Select 2024/2025 POST UTME application',
'Enter UTME Registration Number',
'Pay N2,000 application fee',
'Complete application form and attach passport (JPEG format)'
],
'post_utme_fee': 'N2,000',
'predegree_fee': 'N10,000',
'acceptance_fee': 'N50,000'
},
# Fees Structure
'fees': {
'new_students': {
'non_science': {'total': 175550, 'first_semester': 105330, 'second_semester': 70220},
'science': {'total': 200550, 'first_semester': 120330, 'second_semester': 80220},
'technology': {'total': 210550, 'first_semester': 126330, 'second_semester': 84220}
},
'returning_students': {
'non_science': {'total': 145550, 'first_semester': 87330, 'second_semester': 58220},
'science': {'total': 170550, 'first_semester': 102330, 'second_semester': 68220},
'technology': {'total': 180550, 'first_semester': 108330, 'second_semester': 72220}
},
'acceptance_fee': 50000
},
# Academic Programs
'programs': {
'biological_science': ['Science Laboratory Technology', 'Microbiology', 'Plant Science and Biotechnology'],
'health_science': ['Health Information Management', 'Public Health'],
'languages': ['English Education', 'French Education', 'English & Literary Studies'],
'management_science': ['Accounting', 'Business Administration', 'Office and Information Management', 'Procurement Management'],
'performing_arts': ['Theatre Arts', 'Music'],
'liberal_arts': ['French', 'History & International Studies', 'Islamic Studies', 'Linguistics', 'Religious Studies', 'Theology', 'Yoruba'],
'educational_foundations': ['Educational Management'],
'educational_technology': ['Educational Technology', 'Library & Information Science'],
'peace_security': ['Peace and Conflict Studies', 'Criminology and Security Studies', 'Social Work'],
'science_education': ['Mathematics Education', 'Physics Education', 'Biology Education', 'Chemistry Education', 'Integrated Science', 'Agricultural Science Education'],
'health_education': ['Health Education', 'Human Kinetics and Sport Science'],
'social_science_education': ['Social Studies Education', 'Economics Education', 'Geography Education', 'Political Science Education'],
'chemical_science': ['Industrial Chemistry', 'Biochemistry'],
'vocational_education': ['Agricultural Science Education', 'Home Economics Education', 'Industrial Technology Education'],
'business_education': ['Business Education'],
'counselling_psychology': ['Early Childhood Education', 'Guidance and Counselling'],
'mathematical_science': ['Industrial Mathematics', 'Mathematics', 'Statistics'],
'computing': ['Computer Science'],
'physics': ['Physics with Electronics'],
'economics': ['Cooperative and Rural Development', 'Economics'],
'communication': ['Mass Communication'],
'geography': ['Environmental Management', 'Transport & Logistics Management'],
'political_science': ['Political Science'],
'agriculture': ['Agricultural Economics & Extension', 'Animal Science', 'Aquaculture & Fisheries'],
'food_science': ['Food Science and Technology', 'Nutrition & Dietetics'],
'engineering': ['Civil Engineering', 'Electrical and Electronics Engineering', 'Mechanical Engineering'],
'architecture': ['Architecture', 'Estate Management'],
'building_technology': ['Building Technology', 'Quantity Surveying'],
'design_arts': ['Clothing and Textiles', 'Fashion Design', 'Industrial Design'],
'entrepreneurial': ['Entrepreneurial Studies'],
'tourism': ['Hospitality Management & Tourism']
},
# Documents for Screening
'screening_documents': [
'OβLevel results (WAEC, NECO, or NABTEB).',
'JAMB UTME result slip.',
'JAMB admission letter',
'Birth certificate or age declaration.',
'Passport photographs.',
'Local Government Identification.',
'Bio-data form',
'School fees payment receipt',
'For Direct Entry, additional documents including A-Level results, HND certificates, or transcripts are required'
]
}
# Create response templates
self.responses = {
'greeting': [
"Hello! Welcome to BOUESTI Virtual Assistant. I'm here to help you with information about Bamidele Olumilua University of Education, Science, and Technology, Ikere Ekiti. How can I assist you today?",
"Hi there! I'm the BOUESTI Virtual Assistant. I can help you with admissions, programs, fees, and general information about our university. What would you like to know?",
"Welcome to BOUESTI! I'm here to help prospective students with information about our university. How can I help you today?"
],
'goodbye': [
"Thank you for using BOUESTI Virtual Assistant! If you have more questions, feel free to contact us at [email protected] or +234-805-797-5157. Good luck with your application!",
"Goodbye! Remember to visit portal.bouesti.edu.ng for applications. We look forward to welcoming you to BOUESTI!",
"Thank you for your interest in BOUESTI! Contact us anytime for more information. Best wishes!"
],
'thanks': [
"You're welcome! Is there anything else you'd like to know about BOUESTI?",
"Glad I could help! Feel free to ask if you have more questions.",
"You're welcome! I'm here to help with any other questions about BOUESTI."
],
'default': [
"I'm not sure about that specific question. Could you please rephrase or ask about admissions, programs, fees, or general university information?",
"I don't have information about that topic. Try asking about BOUESTI's admission requirements, academic programs, or fees.",
"I can help you with questions about BOUESTI admissions, programs, fees, and general information. Could you please ask about one of these topics?"
],
'screening_documents': [
'The Documents Required for Screening are: \n1. OβLevel results (WAEC, NECO, or NABTEB).\n2. JAMB UTME result slip.\n3. JAMB admission letter\n4. Birth certificate or age declaration.\n5. Passport photographs.\n6. Local Government Identification.\n7. Bio-data form\n8. School fees payment receipt\n9. For Direct Entry, additional documents including A-Level results, HND certificates, or transcripts are required'
]
}
# Create pattern-response pairs for intent recognition
self.patterns = {
'greeting': [
r'hello|hi|hey|good morning|good afternoon|good evening',
r'start|begin|help'
],
'goodbye': [
r'bye|goodbye|see you|thanks and bye|exit|quit'
],
'thanks': [
r'thank you|thanks|thank|appreciate'
],
'admission_requirements': [
r'admission|requirement|qualify|eligible|utme|score|olevel|waec|ssce|direct entry',
r'how to apply|application requirement|minimum score|cut off|jamb'
],
'application_process': [
r'how to apply|application process|post utme|predegree|apply online',
r'application steps|registration|signup|create account'
],
'fees': [
r'fees|cost|tuition|payment|price|expensive|cheap|money|naira',
r'how much|school fees|acceptance fee|installment'
],
'programs': [
r'program|course|study|department|faculty|degree|major|field',
r'what can i study|available courses|list of programs'
],
'contact': [
r'contact|phone|email|address|location|reach|call',
r'contact information|how to reach|office|support'
],
'university_info': [
r'about|university|bouesti|history|mission|vision|ranking',
r'tell me about|information about|what is bouesti'
],
'admission_status': [
r'admission status|check admission|admitted|admission letter|print letter',
r'am i admitted|admission result|jamb caps'
],
'payment_process': [
r'how to pay|payment process|online payment|remitta|rrr',
r'pay fees|payment method|card payment|acceptance fee payment'
],
'screening_documents': [
r'\bscreening\b.*\bdocuments\b',
r'\bdocuments\b.*\bscreening\b',
r'what.*screening.*document',
r'require.*screening.*document',
r'document.*required.*screening',
r'checklist.*screening',
r'document.*screening',
],
'guide_request': [
r'\bguide me\b',
r'\bhelp guide\b',
r'\bshow.*guide\b'
]
}
self.vectorizer = TfidfVectorizer(tokenizer=self.tokenize, lowercase=True)
self.setup_vectorizer()
def tokenize(self, text):
"""Tokenize and lemmatize text"""
tokens = word_tokenize(text.lower())
return [self.lemmatizer.lemmatize(token) for token in tokens
if token not in string.punctuation and token not in self.stop_words]
def setup_vectorizer(self):
"""Setup TF-IDF vectorizer with knowledge base"""
corpus = []
for category, content in self.knowledge_base.items():
if isinstance(content, dict):
for key, value in content.items():
if isinstance(value, str):
corpus.append(value)
elif isinstance(value, list):
corpus.extend([str(item) for item in value])
elif isinstance(content, list):
corpus.extend([str(item) for item in content])
# Add pattern texts
for intent, patterns in self.patterns.items():
corpus.extend(patterns)
self.vectorizer.fit(corpus)
def detect_intent(self, user_input):
"""Detect user intent based on patterns"""
user_input_lower = user_input.lower()
# Check for user name if the bot is awaiting a name
if self.awaiting_name:
name_match = re.search(r"(?:my name is|i am|it's|this is)?\s*([a-zA-Z]+)", user_input_lower)
if name_match:
self.user_name = name_match.group(1).capitalize()
self.awaiting_name = False # Reset the flag
return 'name_provided'
# If it's just one word and alphabetic, assume it's the name
if user_input_lower.isalpha() and len(user_input_lower.split()) == 1:
self.user_name = user_input_lower.capitalize()
self.awaiting_name = False
return 'name_provided'
for intent, patterns in self.patterns.items():
for pattern in patterns:
if re.search(pattern, user_input_lower):
return intent
return 'unknown'
def get_admission_requirements_response(self):
"""Get admission requirements information"""
req = self.knowledge_base['admission_requirements']
return f"""π **BOUESTI Admission Requirements:**
π― **UTME Score:** Minimum of {req['utme_score']} marks
π **O'Level Requirements:** {req['olevel_requirements']}
π **Direct Entry:** {req['direct_entry']}
π **JAMB Requirements:** {req['jamb_requirements']}
**Important:** Ensure your UTME subject combinations are relevant to your chosen course of study."""
def get_application_process_response(self):
"""Get application process information"""
steps = self.knowledge_base['application_process']['post_utme_steps']
fee = self.knowledge_base['application_process']['post_utme_fee']
response = f"""π **How to Apply for BOUESTI Post UTME:**
**Application Fee:** {fee}
**Steps:**
"""
for i, step in enumerate(steps, 1):
response += f"{i}. {step}\n"
response += f"""
**Pre-Degree Application Fee:** {self.knowledge_base['application_process']['predegree_fee']}
**Acceptance Fee:** {self.knowledge_base['application_process']['acceptance_fee']}"""
return response
def get_fees_response(self):
"""Get fees information"""
new_fees = self.knowledge_base['fees']['new_students']
returning_fees = self.knowledge_base['fees']['returning_students']
return f"""π° **BOUESTI Fees Structure (2023/2024 Session):**
**Acceptance Fee:** β¦{self.knowledge_base['fees']['acceptance_fee']:,} (All Programs)
**NEW STUDENTS:**
β’ Non-Science: β¦{new_fees['non_science']['total']:,} total
β’ Science: β¦{new_fees['science']['total']:,} total
β’ Technology: β¦{new_fees['technology']['total']:,} total
**RETURNING STUDENTS (200L-500L):**
β’ Non-Science: β¦{returning_fees['non_science']['total']:,} total
β’ Science: β¦{returning_fees['science']['total']:,} total
β’ Technology: β¦{returning_fees['technology']['total']:,} total
**Payment Options:** 60% first semester, 40% second semester
**Installment payments available**"""
def get_programs_response(self):
"""Get academic programs information"""
response = "π **BOUESTI Academic Programs:**\n\n"
program_categories = [
('Engineering', 'engineering'),
('Sciences', 'biological_science'),
('Management', 'management_science'),
('Education', 'science_education'),
('Health Sciences', 'health_science'),
('Liberal Arts', 'liberal_arts'),
('Technology', 'computing')
]
for category_name, category_key in program_categories:
if category_key in self.knowledge_base['programs']:
programs = self.knowledge_base['programs'][category_key]
response += f"**{category_name}:**\n"
for program in programs[:3]: # Show first 3 programs
response += f"β’ B.Sc./B.Tech/B.A. {program}\n"
response += "\n"
response += "π **Total:** 70+ degree programs across all faculties\n"
response += "For complete list, visit: portal.bouesti.edu.ng"
return response
def get_contact_response(self):
"""Get contact information"""
contact = self.knowledge_base['university_info']
return f"""π **BOUESTI Contact Information:**
ποΈ **University:** {contact['name']}
π **Website:** {contact['website']}
π§ **Email:** {', '.join(contact['contact_email'])}
π± **Phone:** {', '.join(contact['contact_phone'])}
π **Location:** {contact['location']}
**Admission Enquiries:**
β’ +234-814-008-0237
β’ +234-701-930-3769"""
def get_university_info_response(self):
"""Get general university information"""
info = self.knowledge_base['university_info']
return f"""ποΈ **About BOUESTI:**
**Full Name:** {info['name']}
**Acronym:** {info['acronym']}
**Location:** {info['location']}
**Ranking:** {info['ranking']}
**Mission:** {info['mission']}
**Vision:** {info['vision']}
**Quick Facts:**
β’ 70+ degree programs
β’ Full NUC accreditation for 42 programs
β’ Modern facilities and equipment
β’ Experienced faculty"""
def get_admission_status_response(self):
"""Get admission status checking information"""
return """π **How to Check BOUESTI Admission Status:**
1. Visit portal.bouesti.edu.ng
2. Click on "Check Admission Status"
3. Enter your JAMB Registration Number
4. Select "2024/2025 Session"
5. Choose "DEGREE" as Admission Type
6. Use your JAMB REG as USERNAME
**If Admitted:** You'll be redirected to print your admission letter
**If Not Yet Admitted:** You'll see "NOT YET ADMITTED, ADMISSION IS DONE IN BATCHES"
**Important:** Accept your admission immediately on JAMB CAPS once offered!"""
def get_payment_process_response(self):
"""Get payment process information"""
return """π³ **BOUESTI Payment Process:**
**For Acceptance Fee:**
1. Visit portal.bouesti.edu.ng
2. Click "Student Login"
3. Username: Your JAMB REG
4. Password: password1
5. Complete bio-data
6. Click "Fees Payment"
7. Select "ACCEPTANCE"
8. Follow payment procedures
**For All Fee Payments:**
1. Login to your dashboard
2. Click "FEES"
3. Select "FEES PAYMENT"
4. Choose payment type (ACCEPTANCE, TUITION, HOSTEL)
5. Generate Remitta (RRR)
6. Complete payment
**Payment Methods:** ATM Card, Online Banking, Bank Transfer"""
def get_screening_documents_response(self):
"""Get required documents for screening"""
documents = self.knowledge_base['screening_documents']
response = 'The Documents Required for Screening are: \n'
for i, doc in enumerate(documents, 1):
response += f"{i}. {doc}\n"
return response
def generate_response(self, user_input):
"""Generate response based on user input"""
intent = self.detect_intent(user_input)
if intent == 'guide_request':
return "π§ No problem! Please download the [Guide to Using this Chatbot](https://wa.me/2349120744751)."
if self.first_greeting and intent == 'greeting':
self.first_greeting = False
self.awaiting_name = True # Set flag to true after the first greeting
return "Hey friend π, I am BOUESTI Chatbot, you can give me a name or simply call me a Chatbot, what is your name?"
if intent == 'name_provided' and self.user_name:
# This intent is handled in detect_intent and sets self.user_name
return f"Nice to have you {self.user_name}, π€ do you want to know about admissions, courses, tuition or more at BOUESTI?"
if intent == 'greeting':
return random.choice(self.responses['greeting'])
if intent == 'goodbye':
return random.choice(self.responses['goodbye'])
elif intent == 'thanks':
return random.choice(self.responses['thanks'])
elif intent == 'admission_requirements':
return self.get_admission_requirements_response()
elif intent == 'application_process':
return self.get_application_process_response()
elif intent == 'fees':
return self.get_fees_response()
elif intent == 'programs':
return self.get_programs_response()
elif intent == 'contact':
return self.get_contact_response()
elif intent == 'university_info':
return self.get_university_info_response()
elif intent == 'admission_status':
return self.get_admission_status_response()
elif intent == 'payment_process':
return self.get_payment_process_response()
elif intent == 'screening_documents':
return self.get_screening_documents_response()
else:
return random.choice(self.responses['default'])
def create_gradio_interface(self):
"""Create Gradio interface"""
with gr.Blocks(
title="BOUESTI Virtual Assistant",
theme=gr.themes.Soft(),
css="""
.gradio-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.chatbot {
height: 400px;
}
.header-text {
text-align: center;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 10px;
margin-bottom: 20px;
}
.instruction-box {
border: 2px solid #e0e0e0;
padding: 15px;
border-radius: 10px;
margin-bottom: 15px;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
"""
) as interface:
# Header
gr.HTML("""
<div class="header-text">
<h1>π BOUESTI Virtual Assistant</h1>
<h3>Bamidele Olumilua University of Education, Science, and Technology</h3>
<p>Get instant answers about admissions, programs, fees, and more!</p>
</div>
""")
# Chat interface
with gr.Row():
with gr.Column(scale=4):
chatbot = gr.Chatbot(
[],
elem_id="chatbot",
bubble_full_width=False,
height=400,
show_label=False,
elem_classes=["chatbot"]
)
with gr.Row():
msg = gr.Textbox(
placeholder="Ask me about BOUESTI admissions, programs, fees, or any other questions...",
container=False,
scale=7,
show_label=False
)
submit_btn = gr.Button("Send", variant="primary", scale=1)
clear_btn = gr.Button("Clear Chat", variant="secondary", size="sm")
with gr.Column(scale=2):
# Instruction box
gr.HTML("""
<div class="instruction-box">
<h4>π‘ Quick Help</h4>
<p>Whenever you are stuck, enter the magic word:</p>
<p><strong style="color: #591305; font-size: 1.1em;">Guide me</strong></p>
</div>
""")
# Quick buttons
gr.HTML("<h4>π Quick Actions</h4>")
quick_btns = [
("π Admission Requirements", "admission requirements"),
("π° Fees Structure", "fees"),
("π Programs", "programs"),
("π Contact Info", "contact"),
("π Screening Documents", "screening documents")
]
quick_buttons = []
for btn_text, btn_value in quick_btns:
btn = gr.Button(btn_text, variant="outline", size="sm")
quick_buttons.append((btn, btn_value))
# Event handlers
def respond(message, history):
if not message.strip():
return history, ""
# Generate response
response = self.generate_response(message)
# Add to history
history.append([message, response])
return history, ""
def clear_chat():
return [], ""
def quick_response(quick_msg, history):
return respond(quick_msg, history)
# Button events
submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
msg.submit(respond, [msg, chatbot], [chatbot, msg])
clear_btn.click(clear_chat, [], [chatbot, msg])
# Quick button events
for btn, value in quick_buttons:
btn.click(
lambda x=value: quick_response(x, []),
[],
[chatbot, msg]
)
return interface
# Initialize and launch the chatbot
def main():
chatbot = BOUESTIChatbot()
interface = chatbot.create_gradio_interface()
interface.launch()
if __name__ == "__main__":
main() |