forked from rctatman/minimal_flask_example_heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
40 lines (33 loc) · 1.19 KB
/
script.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
import json
from flask import Flask, request
from serve import get_keywords_api
# I've commented out the last import because it won't work in kernels,
# but you should uncomment it when we build our app tomorrow
# create an instance of Flask
app = Flask(__name__)
# This will print some text at our app's URL
# so that we can check that it's working. If you
# wanted a more complex UI you could put it here.
@app.route('/')
def index():
return "Up and running!"
# load our pre-trained model & function
keywords_api = get_keywords_api()
# Define a post method for our API.
@app.route('/extractpackages', methods=['POST'])
def extractpackages():
"""
Takes in a json file, extracts the keywords &
their indices and then returns them as a json file.
"""
# the data the user input, in json format
input_data = request.json
# use our API function to get the keywords
output_data = keywords_api(input_data)
# convert our dictionary into a .json file
# (returning a dictionary wouldn't be very
# helpful for someone querying our API from
# java; JSON is more flexible/portable)
response = json.dumps(output_data)
# return our json file
return response