Sephfox commited on
Commit
e153d74
·
verified ·
1 Parent(s): 88945ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -128,8 +128,7 @@ def evolve_emotions():
128
  toolbox.register("attr_float", random.uniform, 0, 20)
129
  toolbox.register("attr_intensity", random.uniform, 0, 10)
130
  toolbox.register("individual", tools.initCycle, creator.Individual,
131
- (toolbox.attr_float,) * (len(emotions) - 1)
132
- +
133
  (toolbox.attr_intensity,) * len(emotions) +
134
  (lambda: 100,), n=1)
135
  toolbox.register("population", tools.initRepeat, list, toolbox.individual)
@@ -154,10 +153,10 @@ def evolve_emotions():
154
  emotions['ideal_state']['percentage'] = ideal_state
155
 
156
  def predict_emotion(context):
157
- emotion_prediction_pipeline = pipeline('text-classification', model=emotion_prediction_model, tokenizer=emotion_prediction_tokenizer, return_all_scores=True)
158
  predictions = emotion_prediction_pipeline(context)
159
  emotion_scores = predictions[0]
160
- emotion_pred = max(emotion_scores, key=emotion_scores.get)
161
  return emotion_pred
162
 
163
  def generate_text(prompt, max_length=100, emotion=None):
@@ -203,4 +202,4 @@ with gr.Blocks() as demo:
203
 
204
  predict_btn.click(fn=lambda context: (predict_emotion(context), generate_response(context, emotion=predict_emotion(context))), inputs=context_input, outputs=[emotion_output, generated_text_output])
205
 
206
- demo.launch()
 
128
  toolbox.register("attr_float", random.uniform, 0, 20)
129
  toolbox.register("attr_intensity", random.uniform, 0, 10)
130
  toolbox.register("individual", tools.initCycle, creator.Individual,
131
+ (toolbox.attr_float,) * (len(emotions) - 1) +
 
132
  (toolbox.attr_intensity,) * len(emotions) +
133
  (lambda: 100,), n=1)
134
  toolbox.register("population", tools.initRepeat, list, toolbox.individual)
 
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, top_k=None)
157
  predictions = emotion_prediction_pipeline(context)
158
  emotion_scores = predictions[0]
159
+ emotion_pred = emotion_classes[np.argmax(emotion_scores)]
160
  return emotion_pred
161
 
162
  def generate_text(prompt, max_length=100, emotion=None):
 
202
 
203
  predict_btn.click(fn=lambda context: (predict_emotion(context), generate_response(context, emotion=predict_emotion(context))), inputs=context_input, outputs=[emotion_output, generated_text_output])
204
 
205
+ demo.launch(share=True)