szoya commited on
Commit
0972aa8
·
verified ·
1 Parent(s): bd13b09

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import spacy
4
+
5
+ app = FastAPI(title="spaCy NER API")
6
+
7
+ # Load transformer model
8
+ nlp = spacy.load(
9
+ "en_core_web_trf",
10
+ disable=["tagger", "parser", "lemmatizer", "attribute_ruler"]
11
+ )
12
+
13
+ class TextInput(BaseModel):
14
+ text: str
15
+
16
+
17
+ @app.post("/ner")
18
+ def extract_ner(data: TextInput):
19
+ doc = nlp(data.text)
20
+
21
+ entities = []
22
+ for ent in doc.ents:
23
+ entities.append({
24
+ "text": ent.text,
25
+ "label": ent.label_
26
+ })
27
+
28
+ return {"entities": entities}