added training xgboost code
Browse files
app.py
CHANGED
@@ -48,6 +48,16 @@ tokenizer_model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
|
|
48 |
mental_classifier_model_path = "mental_health_model.pkl"
|
49 |
mental_classifier = MentalHealthClassifier(data_path, mental_classifier_model_path)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# Function to display Q-table
|
53 |
def display_q_table(q_values, states, actions):
|
@@ -82,10 +92,10 @@ def speech_recognition_callback():
|
|
82 |
|
83 |
|
84 |
def remove_html_tags(text):
|
85 |
-
clean_text = re.sub("<.*?>", "", text)
|
|
|
86 |
return clean_text
|
87 |
|
88 |
-
|
89 |
# Initialize memory
|
90 |
if "entered_text" not in st.session_state:
|
91 |
st.session_state.entered_text = []
|
@@ -254,7 +264,7 @@ if user_message:
|
|
254 |
|
255 |
llm_model = LLLResponseGenerator()
|
256 |
temperature = 0.5
|
257 |
-
max_length = 128
|
258 |
|
259 |
# Collect all messages exchanged so far into a single text string
|
260 |
all_messages = "\n".join(
|
@@ -271,6 +281,7 @@ if user_message:
|
|
271 |
Response;
|
272 |
"""
|
273 |
context = f"You are a mental health supporting non-medical assistant. Provide some advice and ask a relevant question back to the user. {all_messages}"
|
|
|
274 |
|
275 |
llm_response = llm_model.llm_inference(
|
276 |
model_type="huggingface",
|
|
|
48 |
mental_classifier_model_path = "mental_health_model.pkl"
|
49 |
mental_classifier = MentalHealthClassifier(data_path, mental_classifier_model_path)
|
50 |
|
51 |
+
if not os.path.exists(mental_classifier_model_path):
|
52 |
+
mental_classifier.initialize_tokenizer(tokenizer_model_name)
|
53 |
+
X, y = mental_classifier.preprocess_data()
|
54 |
+
y_test, y_pred = mental_classifier.train_model(X, y)
|
55 |
+
mental_classifier.save_model()
|
56 |
+
else:
|
57 |
+
mental_classifier.load_model()
|
58 |
+
mental_classifier.initialize_tokenizer(tokenizer_model_name) # Ensure tokenizer is initialized if loading model from pickle
|
59 |
+
X, y = mental_classifier.preprocess_data() # Preprocess data again if needed
|
60 |
+
mental_classifier.model.fit(X, y) # Fit the loaded model to the data
|
61 |
|
62 |
# Function to display Q-table
|
63 |
def display_q_table(q_values, states, actions):
|
|
|
92 |
|
93 |
|
94 |
def remove_html_tags(text):
|
95 |
+
# clean_text = re.sub("<.*?>", "", text)
|
96 |
+
clean_text = re.sub(r'<.*?>|- |"|\\n', '', text)
|
97 |
return clean_text
|
98 |
|
|
|
99 |
# Initialize memory
|
100 |
if "entered_text" not in st.session_state:
|
101 |
st.session_state.entered_text = []
|
|
|
264 |
|
265 |
llm_model = LLLResponseGenerator()
|
266 |
temperature = 0.5
|
267 |
+
max_length = 128 * 4
|
268 |
|
269 |
# Collect all messages exchanged so far into a single text string
|
270 |
all_messages = "\n".join(
|
|
|
281 |
Response;
|
282 |
"""
|
283 |
context = f"You are a mental health supporting non-medical assistant. Provide some advice and ask a relevant question back to the user. {all_messages}"
|
284 |
+
# context = f"You are a Mindful Media Mentor, dedicated to providing compassionate support and guidance to users facing mental health challenges. Your goal is to foster a safe and understanding environment where users feel heard and supported. Draw from your expertise to offer practical advice and resources, and encourage users to explore their feelings and experiences openly. Your responses should aim to empower users to take positive steps towards their well-being. {all_messages}"
|
285 |
|
286 |
llm_response = llm_model.llm_inference(
|
287 |
model_type="huggingface",
|