Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -153,13 +153,13 @@ def evolve_emotions():
|
|
153 |
emotions['ideal_state']['percentage'] = ideal_state
|
154 |
|
155 |
def predict_emotion(context):
|
156 |
-
emotion_prediction_pipeline = pipeline('text-classification', model=emotion_prediction_model, tokenizer=emotion_prediction_tokenizer,
|
157 |
predictions = emotion_prediction_pipeline(context)
|
158 |
-
emotion_scores = {prediction['label']: prediction['score'] for prediction in predictions}
|
159 |
emotion_pred = max(emotion_scores, key=emotion_scores.get)
|
160 |
return emotion_pred
|
161 |
|
162 |
-
def generate_text(prompt,
|
163 |
finetuned_lm_tokenizer, finetuned_lm_model = get_finetuned_lm_model()
|
164 |
input_ids = finetuned_lm_tokenizer.encode(prompt, return_tensors='pt')
|
165 |
attention_mask = torch.ones(input_ids.shape, dtype=torch.long)
|
|
|
153 |
emotions['ideal_state']['percentage'] = ideal_state
|
154 |
|
155 |
def predict_emotion(context):
|
156 |
+
emotion_prediction_pipeline = pipeline('text-classification', model=emotion_prediction_model, tokenizer=emotion_prediction_tokenizer, return_all_scores=True)
|
157 |
predictions = emotion_prediction_pipeline(context)
|
158 |
+
emotion_scores = {prediction['label']: prediction['score'] for prediction in predictions[0]}
|
159 |
emotion_pred = max(emotion_scores, key=emotion_scores.get)
|
160 |
return emotion_pred
|
161 |
|
162 |
+
def generate_text(prompt, emotion=None, max_length=100):
|
163 |
finetuned_lm_tokenizer, finetuned_lm_model = get_finetuned_lm_model()
|
164 |
input_ids = finetuned_lm_tokenizer.encode(prompt, return_tensors='pt')
|
165 |
attention_mask = torch.ones(input_ids.shape, dtype=torch.long)
|