Update app.py
Browse files
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 |
-
|
| 10 |
def predict_emotion(text):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 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,
|