MJobe commited on
Commit
11d5e31
1 Parent(s): d167323

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -6
main.py CHANGED
@@ -135,18 +135,19 @@ async def test_classify_text(text: str = Form(...)):
135
  # Perform text classification using the updated model that returns positive, neutral, or negative
136
  result = nlp_classification_v2(text)
137
 
138
- # Get the label (positive, neutral, negative) and format it as required
139
- label = result[0]['label']
 
140
 
141
  # Map the model labels to human-readable format
142
  label_map = {
143
- "LABEL_0": "Negative", # Cardiff NLP's model may use these labels
144
- "LABEL_1": "Neutral", # Remap LABEL_1 to Neutral
145
- "LABEL_2": "Positive" # LABEL_2 corresponds to Positive
146
  }
147
 
148
  # Get the readable label from the map
149
- formatted_label = label_map.get(label, "Unknown")
150
 
151
  return {"label": formatted_label, "score": result[0]['score']}
152
  except Exception as e:
 
135
  # Perform text classification using the updated model that returns positive, neutral, or negative
136
  result = nlp_classification_v2(text)
137
 
138
+ # Print the raw label for debugging purposes (can be removed later)
139
+ raw_label = result[0]['label']
140
+ print(f"Raw label from model: {raw_label}")
141
 
142
  # Map the model labels to human-readable format
143
  label_map = {
144
+ "negative": "Negative",
145
+ "neutral": "Neutral",
146
+ "positive": "Positive"
147
  }
148
 
149
  # Get the readable label from the map
150
+ formatted_label = label_map.get(raw_label, "Unknown")
151
 
152
  return {"label": formatted_label, "score": result[0]['score']}
153
  except Exception as e: