Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from sklearn.model_selection import train_test_split
|
|
10 |
from sklearn.preprocessing import OneHotEncoder
|
11 |
from sklearn.neural_network import MLPClassifier
|
12 |
from deap import base, creator, tools, algorithms
|
13 |
-
from transformers import
|
14 |
import torch
|
15 |
import torch.multiprocessing as mp
|
16 |
|
@@ -160,46 +160,9 @@ def get_emotional_response(context):
|
|
160 |
prediction = model.predict(context_encoded)
|
161 |
predicted_emotion = emotion_classes[prediction[0]]
|
162 |
|
163 |
-
#
|
164 |
-
|
165 |
-
|
166 |
-
print("Anomalous context detected. Adjusting emotional response.")
|
167 |
-
update_emotion('calmness', 20)
|
168 |
-
else:
|
169 |
-
# Define emotional responses
|
170 |
-
if predicted_emotion == 'joy':
|
171 |
-
update_emotion('joy', 20)
|
172 |
-
update_emotion('pleasure', 20)
|
173 |
-
elif predicted_emotion == 'sadness':
|
174 |
-
update_emotion('sadness', 20)
|
175 |
-
update_emotion('grief', 20)
|
176 |
-
elif predicted_emotion == 'anger':
|
177 |
-
update_emotion('anger', 20)
|
178 |
-
elif predicted_emotion == 'determination':
|
179 |
-
update_emotion('determination', 20)
|
180 |
-
elif predicted_emotion == 'resentment':
|
181 |
-
update_emotion('resentment', 20)
|
182 |
-
elif predicted_emotion == 'glory':
|
183 |
-
update_emotion('glory', 20)
|
184 |
-
elif predicted_emotion == 'motivation':
|
185 |
-
update_emotion('motivation', 20)
|
186 |
-
elif predicted_emotion == 'surprise':
|
187 |
-
update_emotion('surprise', 20)
|
188 |
-
elif predicted_emotion == 'fear':
|
189 |
-
update_emotion('fear', 20)
|
190 |
-
elif predicted_emotion == 'trust':
|
191 |
-
update_emotion('trust', 20)
|
192 |
-
elif predicted_emotion == 'disgust':
|
193 |
-
update_emotion('disgust', 20)
|
194 |
-
elif predicted_emotion == 'optimism':
|
195 |
-
update_emotion('optimism', 20)
|
196 |
-
elif predicted_emotion == 'pessimism':
|
197 |
-
update_emotion('pessimism', 20)
|
198 |
-
elif predicted_emotion == 'boredom':
|
199 |
-
update_emotion('boredom', 20)
|
200 |
-
elif predicted_emotion == 'envy':
|
201 |
-
update_emotion('envy', 20)
|
202 |
-
|
203 |
# Evolve emotions
|
204 |
evolve_emotions()
|
205 |
|
@@ -209,10 +172,10 @@ def get_emotional_response(context):
|
|
209 |
|
210 |
return f"Emotion: {predicted_emotion}, Emotion Details: {emotions[predicted_emotion]}"
|
211 |
|
212 |
-
# Initialize the pre-trained language model
|
213 |
-
model_name = '
|
214 |
-
tokenizer =
|
215 |
-
lm_model =
|
216 |
|
217 |
# Multiprocessing context setting (ensure it's set only once)
|
218 |
if __name__ == '__main__':
|
|
|
10 |
from sklearn.preprocessing import OneHotEncoder
|
11 |
from sklearn.neural_network import MLPClassifier
|
12 |
from deap import base, creator, tools, algorithms
|
13 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
14 |
import torch
|
15 |
import torch.multiprocessing as mp
|
16 |
|
|
|
160 |
prediction = model.predict(context_encoded)
|
161 |
predicted_emotion = emotion_classes[prediction[0]]
|
162 |
|
163 |
+
# Update emotions based on predicted emotion
|
164 |
+
update_emotion(predicted_emotion, 20)
|
165 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
# Evolve emotions
|
167 |
evolve_emotions()
|
168 |
|
|
|
172 |
|
173 |
return f"Emotion: {predicted_emotion}, Emotion Details: {emotions[predicted_emotion]}"
|
174 |
|
175 |
+
# Initialize the pre-trained language model (Phi 3 Mini)
|
176 |
+
model_name = 'microsoft/phi3-mini'
|
177 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, force_download=True)
|
178 |
+
lm_model = AutoModelForCausalLM.from_pretrained(model_name, force_download=True)
|
179 |
|
180 |
# Multiprocessing context setting (ensure it's set only once)
|
181 |
if __name__ == '__main__':
|