Adedayo2000 commited on
Commit
6d05af0
·
verified ·
1 Parent(s): 69cb76a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -31,6 +31,11 @@ except Exception as e:
31
  logger.error(f"Failed to load model: {e}")
32
  classifier = None
33
 
 
 
 
 
 
34
  class TextInput(BaseModel):
35
  text: str
36
 
@@ -79,10 +84,18 @@ def predict(input: TextInput):
79
 
80
  try:
81
  result = classifier(input.text)[0]
 
 
 
 
 
 
 
82
  return {
83
  "text": input.text,
84
- "sentiment": result["label"],
85
- "confidence": round(result["score"], 4)
 
86
  }
87
  except Exception as e:
88
  logger.error(f"Prediction error: {e}")
 
31
  logger.error(f"Failed to load model: {e}")
32
  classifier = None
33
 
34
+ LABEL_MAP = {
35
+ "LABEL_0": "NEGATIVE",
36
+ "LABEL_1": "POSITIVE"
37
+ }
38
+
39
  class TextInput(BaseModel):
40
  text: str
41
 
 
84
 
85
  try:
86
  result = classifier(input.text)[0]
87
+
88
+ raw_label = result["label"]
89
+ sentiment = LABEL_MAP.get(raw_label, raw_label)
90
+
91
+ confidence_score = result["score"]
92
+ confidence_percentage = f"{confidence_score * 100:.2f}%"
93
+
94
  return {
95
  "text": input.text,
96
+ "sentiment": sentiment,
97
+ "confidence": confidence_percentage,
98
+ "confidence_score": round(confidence_score, 4)
99
  }
100
  except Exception as e:
101
  logger.error(f"Prediction error: {e}")