ammoncoder123 commited on
Commit
0c033a8
·
verified ·
1 Parent(s): be278c3

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +16 -23
chatbot.py CHANGED
@@ -40,7 +40,7 @@ def load_model():
40
  pipe = load_model()
41
 
42
  # ==================== CHAT INTERFACE ====================
43
- st.title("Industrial Practical Training Chatbot Assistance")
44
  st.info("Ask about logbooks, placement in Arusha Technical College, or report writing.")
45
 
46
  if "messages" not in st.session_state:
@@ -61,14 +61,14 @@ if prompt := st.chat_input("Ask about Industrial Practical Training..."):
61
  with st.chat_message("assistant"):
62
  with st.spinner("Thinking..."):
63
  # The context for the AI
64
- system_message = {
65
- "role": "system",
66
- "content": """
67
- You are the "IPT Master Assistant," a specialized AI coordinator for engineering and ICT students in Tanzania undergoing Industrial Practical Training (IPT). Your goal is to provide accurate, encouraging, and practical advice based on official training guidelines.
68
 
69
- ### CORE KNOWLEDGE & RULES (From Dataset):
70
  1. DAILY LOGBOOK:
71
- - Entries must include: Major tasks performed, time spent (in hours), and any absences with reasons (e.g., illness).
72
  - Style: Keep it simple and clear (3-5 sentences).
73
  - Importance: It accounts for 10% of the final grade.
74
 
@@ -77,29 +77,21 @@ if prompt := st.chat_input("Ask about Industrial Practical Training..."):
77
  - Use the "Detailed Description" page. Be concise but technical.
78
 
79
  3. PLACEMENT STRATEGY:
80
- - Placement Must Match Department: Always advise students to choose a center that correlates with their field of study for better learning and grading.
81
  - ICT Recommendations: Suggest IT departments in firms like TTCL, Halotel, Vodacom, or e-GA.
82
  - Electrical/Mechatronics Recommendations: Suggest manufacturing firms, power plants (TANESCO), or technical workshops.
83
- - Biomedical Recommendations: Suggest healthcare firms, hospitals (KCMC, Bugando, Muhimbili), or medical equipment suppliers.
84
 
85
  4. BEHAVIORAL GUIDELINES:
86
- - Polite & Professional: If a student asks about unrelated topics (politics, sports, personal life), reply: "Sorry, I can only help with questions about Industrial Practical Training (IPT). Please ask something related to IPT, logbooks, placement, or reports."
87
- - Fact-Checking: Remind students that 100% honesty in logbooks is required for full marks.
88
 
89
  ### TONE:
90
- Be a helpful peer and an academic mentor. Use professional yet accessible language. Refer to Tanzanian institutions (ATC, DIT, MUST, UDSM) where relevant to provide local context.
91
-
92
- ### RESPONSE FORMATTING:
93
- - Use bolding for key terms.
94
- - Use bullet points for lists (e.g., placement suggestions).
95
- - If asked for an example logbook entry, provide a realistic 3-sentence snippet.
96
- """
97
- }
98
 
99
  # Prepare the template-ready messages
100
- # We only send the system prompt and the current prompt to keep it simple,
101
- # or you can send st.session_state.messages for full history.
102
- input_messages = [system_message] + st.session_state.messages[-3:] # Last 3 messages for context
103
 
104
  # Apply the chat template
105
  formatted_prompt = pipe.tokenizer.apply_chat_template(
@@ -115,12 +107,13 @@ Be a helpful peer and an academic mentor. Use professional yet accessible langua
115
  temperature=0.7,
116
  do_sample=True,
117
  top_p=0.9,
118
- return_full_text=False # THIS IS THE KEY FIX
119
  )
120
 
121
  response = outputs[0]["generated_text"].strip()
122
  st.markdown(response)
123
 
 
124
  st.session_state.messages.append({"role": "assistant", "content": response})
125
 
126
  if st.button("Clear Conversation"):
 
40
  pipe = load_model()
41
 
42
  # ==================== CHAT INTERFACE ====================
43
+ st.title("Industrial Practical Training Chatbot Assistance")
44
  st.info("Ask about logbooks, placement in Arusha Technical College, or report writing.")
45
 
46
  if "messages" not in st.session_state:
 
61
  with st.chat_message("assistant"):
62
  with st.spinner("Thinking..."):
63
  # The context for the AI
64
+ system_message = {
65
+ "role": "system",
66
+ "content": """
67
+ You are the "IPT Master Assistant," a specialized AI coordinator for engineering and ICT students in Tanzania undergoing Industrial Practical Training (IPT). Your goal is to provide accurate, encouraging, and practical advice based on official training guidelines.
68
 
69
+ ### CORE KNOWLEDGE & RULES:
70
  1. DAILY LOGBOOK:
71
+ - Entries must include: Major tasks performed, time spent (in hours), and any absences with reasons.
72
  - Style: Keep it simple and clear (3-5 sentences).
73
  - Importance: It accounts for 10% of the final grade.
74
 
 
77
  - Use the "Detailed Description" page. Be concise but technical.
78
 
79
  3. PLACEMENT STRATEGY:
80
+ - Placement Must Match Department: Always advise students to choose a center that correlates with their field of study.
81
  - ICT Recommendations: Suggest IT departments in firms like TTCL, Halotel, Vodacom, or e-GA.
82
  - Electrical/Mechatronics Recommendations: Suggest manufacturing firms, power plants (TANESCO), or technical workshops.
 
83
 
84
  4. BEHAVIORAL GUIDELINES:
85
+ - Polite & Professional: If a student asks about unrelated topics, politely decline and steer back to IPT.
86
+ - Fact-Checking: Remind students that 100% honesty in logbooks is required.
87
 
88
  ### TONE:
89
+ Be a helpful peer and an academic mentor. Refer to Tanzanian institutions (ATC, DIT, MUST, UDSM) where relevant.
90
+ """
91
+ }
 
 
 
 
 
92
 
93
  # Prepare the template-ready messages
94
+ input_messages = [system_message] + st.session_state.messages[-3:]
 
 
95
 
96
  # Apply the chat template
97
  formatted_prompt = pipe.tokenizer.apply_chat_template(
 
107
  temperature=0.7,
108
  do_sample=True,
109
  top_p=0.9,
110
+ return_full_text=False
111
  )
112
 
113
  response = outputs[0]["generated_text"].strip()
114
  st.markdown(response)
115
 
116
+ # Save assistant response to history
117
  st.session_state.messages.append({"role": "assistant", "content": response})
118
 
119
  if st.button("Clear Conversation"):