Sephfox commited on
Commit
56009c5
·
verified ·
1 Parent(s): a7402b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -100,6 +100,9 @@ def save_historical_data(historical_data, file_path=emotion_history_file):
100
  emotion_history = load_historical_data()
101
 
102
  def update_emotion(emotion, percentage, intensity):
 
 
 
103
  emotions['ideal_state']['percentage'] -= percentage
104
  emotions[emotion]['percentage'] += percentage
105
  emotions[emotion]['intensity'] = intensity
@@ -178,7 +181,7 @@ def predict_emotion(context):
178
  tokens = emotion_prediction_tokenizer(context, return_tensors='pt', padding=True, truncation=True)
179
  outputs = emotion_prediction_model(**tokens)
180
  logits = outputs.logits
181
- predicted_class = torch.argmax(logits, dim=1)
182
  predicted_emotion = emotion_classes[predicted_class]
183
 
184
  # Get percentage and intensity based on context
@@ -214,4 +217,4 @@ with gr.Blocks() as demo:
214
  submit.click(update_ui, user_input, response)
215
 
216
  if __name__ == "__main__":
217
- demo.launch()
 
100
  emotion_history = load_historical_data()
101
 
102
  def update_emotion(emotion, percentage, intensity):
103
+ if percentage > emotions['ideal_state']['percentage']:
104
+ percentage = emotions['ideal_state']['percentage']
105
+
106
  emotions['ideal_state']['percentage'] -= percentage
107
  emotions[emotion]['percentage'] += percentage
108
  emotions[emotion]['intensity'] = intensity
 
181
  tokens = emotion_prediction_tokenizer(context, return_tensors='pt', padding=True, truncation=True)
182
  outputs = emotion_prediction_model(**tokens)
183
  logits = outputs.logits
184
+ predicted_class = torch.argmax(logits, dim=1).item()
185
  predicted_emotion = emotion_classes[predicted_class]
186
 
187
  # Get percentage and intensity based on context
 
217
  submit.click(update_ui, user_input, response)
218
 
219
  if __name__ == "__main__":
220
+ demo.launch(share=True)