szoya commited on
Commit
4aa41c7
·
verified ·
1 Parent(s): 63a8465

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -2,7 +2,6 @@ from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from transformers import pipeline
4
  from typing import List
5
- import re
6
 
7
  app = FastAPI(title="NER + Emotion API")
8
 
@@ -48,7 +47,7 @@ def home():
48
 
49
 
50
  # ---------------------------------------------------------
51
- # NER ENDPOINT (FAST)
52
  # ---------------------------------------------------------
53
  @app.post("/analyze/ner")
54
  def analyze_ner(data: TextInput):
@@ -61,14 +60,14 @@ def analyze_ner(data: TextInput):
61
 
62
  for entity in results:
63
  label = entity["entity_group"]
64
- text = entity["word"]
65
 
66
  if label == "PER":
67
- persons.append(text)
68
  elif label == "LOC":
69
- locations.append(text)
70
  elif label == "ORG":
71
- organizations.append(text)
72
 
73
  return {
74
  "persons": list(set(persons)),
@@ -115,7 +114,7 @@ def analyze_sentiment(data: SentimentInput):
115
  return {"results": processed_results}
116
 
117
  except Exception as e:
118
- raise HTTPException(status_code=500, detail=str(e)}
119
 
120
 
121
  if __name__ == "__main__":
 
2
  from pydantic import BaseModel
3
  from transformers import pipeline
4
  from typing import List
 
5
 
6
  app = FastAPI(title="NER + Emotion API")
7
 
 
47
 
48
 
49
  # ---------------------------------------------------------
50
+ # NER ENDPOINT
51
  # ---------------------------------------------------------
52
  @app.post("/analyze/ner")
53
  def analyze_ner(data: TextInput):
 
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":
68
+ locations.append(word)
69
  elif label == "ORG":
70
+ organizations.append(word)
71
 
72
  return {
73
  "persons": list(set(persons)),
 
114
  return {"results": processed_results}
115
 
116
  except Exception as e:
117
+ raise HTTPException(status_code=500, detail=str(e))
118
 
119
 
120
  if __name__ == "__main__":