-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflask_app.py
More file actions
42 lines (30 loc) · 895 Bytes
/
flask_app.py
File metadata and controls
42 lines (30 loc) · 895 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
36
37
38
39
40
41
42
from flask import Flask, jsonify
from joblib import load
from preprocess import lemmatization, clean_output
app = Flask(__name__)
pipe = load('trained_bow_logreg.joblib')
@app.route("/")
def hello():
"""
Default route to display "Hello World!" message just to test you are good with flask :).
"""
return "Hello World!"
@app.route("/api/text=<text>")
def my_api(text):
"""
API route to process the input text and return the tags.
Parameters:
text (str): The input text from the user.
Returns:
JSON: A JSON object containing the input text and the predicted tags.
"""
text_clean = lemmatization([text])
output = pipe.predict([text_clean])
output_clean = clean_output(output)
data = {
"text": text,
"tags": output_clean
}
return jsonify(data)
if __name__ == "__main__":
app.run(debug=True)