haripriyaram commited on
Commit
65b3680
·
verified ·
1 Parent(s): 64279c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -6,11 +6,14 @@ from fastai.text.all import load_learner
6
  # Load the trained model
7
  learn = load_learner('emotion_classifier.pkl')
8
 
9
- # Define the prediction function
10
  def predict_emotion(text):
11
- pred, pred_idx, probs = learn.predict(text)
12
- confidence = float(probs[learn.dls.vocab[1].o2i[pred]])
13
- return f"{pred} (confidence: {confidence:.2f})"
 
 
 
14
 
15
  iface = gr.Interface(
16
  fn=predict_emotion,
 
6
  # Load the trained model
7
  learn = load_learner('emotion_classifier.pkl')
8
 
9
+
10
  def predict_emotion(text):
11
+ try:
12
+ pred, pred_idx, probs = learn.predict(text)
13
+ confidence = float(probs[pred_idx])
14
+ return {"label": pred, "confidence": confidence}
15
+ except Exception as e:
16
+ return {"error": str(e)}
17
 
18
  iface = gr.Interface(
19
  fn=predict_emotion,