szoya commited on
Commit
8cd5417
·
verified ·
1 Parent(s): 4aa41c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -49,19 +49,24 @@ def home():
49
  # ---------------------------------------------------------
50
  # NER ENDPOINT
51
  # ---------------------------------------------------------
 
 
 
52
  @app.post("/analyze/ner")
53
  def analyze_ner(data: TextInput):
54
  try:
55
- results = ner_pipeline(data.text, truncation=True)
56
-
 
57
  persons = []
58
  locations = []
59
  organizations = []
60
 
61
  for entity in results:
62
  label = entity["entity_group"]
63
- word = entity["word"]
64
-
 
65
  if label == "PER":
66
  persons.append(word)
67
  elif label == "LOC":
@@ -74,8 +79,9 @@ def analyze_ner(data: TextInput):
74
  "locations": list(set(locations)),
75
  "organizations": list(set(organizations))
76
  }
77
-
78
  except Exception as e:
 
 
79
  raise HTTPException(status_code=500, detail=str(e))
80
 
81
 
 
49
  # ---------------------------------------------------------
50
  # NER ENDPOINT
51
  # ---------------------------------------------------------
52
+ # ---------------------------------------------------------
53
+ # NER ENDPOINT (UPDATED)
54
+ # ---------------------------------------------------------
55
  @app.post("/analyze/ner")
56
  def analyze_ner(data: TextInput):
57
  try:
58
+ # REMOVED truncation=True to fix the 500 error
59
+ results = ner_pipeline(data.text, aggregation_strategy="simple")
60
+
61
  persons = []
62
  locations = []
63
  organizations = []
64
 
65
  for entity in results:
66
  label = entity["entity_group"]
67
+ word = entity["word"].strip()
68
+
69
+ # dslim/bert-base-NER uses these labels:
70
  if label == "PER":
71
  persons.append(word)
72
  elif label == "LOC":
 
79
  "locations": list(set(locations)),
80
  "organizations": list(set(organizations))
81
  }
 
82
  except Exception as e:
83
+ # This will help you see the exact error in HF logs
84
+ print(f"Internal Error: {str(e)}")
85
  raise HTTPException(status_code=500, detail=str(e))
86
 
87