Bwrite commited on
Commit
6c4e8c0
Β·
verified Β·
1 Parent(s): ab8163e

Update app.py

Browse files

ChatBot for Admission Enquiry

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