-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
73 lines (64 loc) · 1.88 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import request, url_for
from flask_api import FlaskAPI, status, exceptions
from flask import jsonify
from newsplease import NewsPlease
import os,sys,inspect
import fnd_system as fnd
app = FlaskAPI(__name__)
api = {
"/": {
"methods":["GET"],
"description": "Internal FND API Server"
},
"/detect": {
"methods": ["POST"],
"parameters": {
"statement":"String",
"subject":"String",
"justification":"String"
},
"description": "Run FND model and return detection results"
},
"/detectURL": {
"methods": ["POST"],
"parameters": {
"url":"String",
},
"description": "Run FND model and return detection results from a URL"
}
}
@app.route("/", methods=['GET'])
def api_home():
return jsonify(api)
@app.route("/detect", methods=['POST'])
def detect():
data = request.json
statement = data['statement']
subject = data['subject']
justification = data['justification']
result = fnd.detect(statement,subject,justification)
return jsonify(result)
@app.route("/detectURL", methods=['POST'])
def detectURL():
data = request.json
url = data['url']
try:
article = NewsPlease.from_url(url)
except:
return jsonify([None, None])
statement = article.title
justification = article.description
try:
subject = data['subject'] if data['subject'] != "" else fnd.get_subject(statement)[0]
except:
result = (False,statement,justification)
return jsonify(result)
# print(subject)
if justification == None:
return jsonify([None, None])
result = fnd.detect(statement,subject,justification)
result=result+(statement,justification,subject)
# print(jsonify(article))
return jsonify(result)
if __name__ == "__main__":
app.run(debug=True)