Pisethan commited on
Commit
d2c8962
·
verified ·
1 Parent(s): 7f5bdbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -3,13 +3,6 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassifica
3
 
4
  # Model details
5
  MODEL_NAME = "Pisethan/sangapac-math"
6
- reverse_label_mapping = {
7
- 0: "arithmetic",
8
- 1: "multiplication",
9
- 2: "division",
10
- 3: "algebra",
11
- 4: "geometry",
12
- }
13
 
14
  # Load model and tokenizer
15
  try:
@@ -27,12 +20,12 @@ def predict(input_text):
27
  try:
28
  # Predict the category
29
  result = classifier(input_text)
30
- label_id = int(result[0]["label"].split("_")[-1]) # Extract label ID
31
- category = reverse_label_mapping[label_id] # Map label to category
32
 
33
  return {
34
- "Category": category,
35
- "Confidence": result[0]["score"],
36
  }
37
  except Exception as e:
38
  return {"Error": str(e)}
 
3
 
4
  # Model details
5
  MODEL_NAME = "Pisethan/sangapac-math"
 
 
 
 
 
 
 
6
 
7
  # Load model and tokenizer
8
  try:
 
20
  try:
21
  # Predict the category
22
  result = classifier(input_text)
23
+ label = result[0]["label"] # Directly use the label provided by the model
24
+ score = result[0]["score"]
25
 
26
  return {
27
+ "Category": label, # No need to remap since the label is already readable
28
+ "Confidence": score,
29
  }
30
  except Exception as e:
31
  return {"Error": str(e)}