-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (30 loc) · 1.02 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from flask import Flask, request
from gliner import GLiNER
from waitress import serve
__version__ = "1.2.1"
app = Flask(__name__)
print("Starting ph-eye version " + __version__)
model_name = os.getenv("MODEL_NAME", "philterd/ph-eye-pii-base")
print("Using model " + model_name)
model = GLiNER.from_pretrained(model_name)
print("Model loaded and ready to serve requests")
@app.route("/status", methods=["GET"])
def status():
return "healthy: " + model_name
@app.route("/find", methods=["POST"])
def find():
try:
r = request.json
text = r["text"]
labels = ["Person"] if "labels" not in r else r["labels"]
threshold = 0.5 if "threshold" not in r else r["threshold"]
if len(labels) == 0:
labels = ["Person"]
entities = model.predict_entities(text, labels, threshold=threshold)
return entities, 200
except Exception as e:
print(str(e))
return str(e), 500
if __name__ == '__main__':
serve(app, host="0.0.0.0", port=5000)