-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
35 lines (26 loc) · 905 Bytes
/
api.py
File metadata and controls
35 lines (26 loc) · 905 Bytes
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
from text import Text
from flask import Flask
from flask import request
app = Flask(__name__)
def validate_payload(payload, fields):
errors = []
for field in fields:
if field not in payload:
errors.append(f"Field '{field}' is required")
return None if len(errors) == 0 else {"errors": errors}
@app.route('/evaluate', methods=['POST'])
def evaluate():
payload = request.json
valid = validate_payload(payload, ["originText", "toCompare"])
if valid is not None:
return valid, 400
text = Text(payload['originText'])
return {"textId": text.evaluate(payload['toCompare'])}
@app.route('/signature', methods=['POST'])
def signature():
payload = request.json
valid = validate_payload(payload, ["text"])
if valid is not None:
return valid, 400
text = Text(payload['text'])
return {"signature": text.signature.__dict__}