|
@@ -1,50 +0,0 @@
|
|
-from fastapi import FastAPI, Body
|
|
|
|
-
|
|
|
|
-from .models import get_model
|
|
|
|
-from .clean_text import text_cleaner, text_formatter
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-app = FastAPI(
|
|
|
|
- title="Name extractor using Spacy",
|
|
|
|
- description="Extract all names from a row text",
|
|
|
|
- version="0.1",
|
|
|
|
-)
|
|
|
|
-model = get_model()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@app.get("/")
|
|
|
|
-async def home():
|
|
|
|
- return {"status": "Server is Up!"}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@app.post('/name')
|
|
|
|
-def is_a_human_name(data: dict = Body(...)):
|
|
|
|
- text = data.get('name')
|
|
|
|
- doc = model(text)
|
|
|
|
- is_name = False
|
|
|
|
- for ent in doc.ents:
|
|
|
|
- if ent.label_ in ['PERSON']:
|
|
|
|
- is_name = True
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- 'name': is_name
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@app.post('/names/all')
|
|
|
|
-def get_all_names(data: dict = Body(...)):
|
|
|
|
- text = data.get('text')
|
|
|
|
- print(text)
|
|
|
|
- text = text_cleaner(text)
|
|
|
|
- text = text_formatter(text)
|
|
|
|
- print(text)
|
|
|
|
- doc = model(text)
|
|
|
|
- names = {
|
|
|
|
- ent.text for ent in doc.ents if ent.label_ in ['PERSON', 'ORG', 'PRODUCT']
|
|
|
|
- }
|
|
|
|
- print(names)
|
|
|
|
- return {
|
|
|
|
- 'names': names
|
|
|
|
- }
|
|
|