-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (29 loc) · 1.02 KB
/
app.py
File metadata and controls
29 lines (29 loc) · 1.02 KB
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
from flask import Flask, request, jsonify, send_from_directory
from flask_cors import CORS
import pickle
import pandas
from name_processing import annotate_name, characterize_name
app = Flask(__name__)
CORS(app)
with open("gam.pkl", "rb") as f:
loaded_gam = pickle.load(f)
@app.route("/<name>")
def home(name):
annotations = annotate_name(name)
predictions = []
for i in range(15):
new_data = pandas.DataFrame({
"decade": [1880+(10*i)],
"stress": [annotations["stress"]],
"syll_count": [annotations["syll_count"]],
"ends_in_vowel": [annotations["ends_in_vowel"]],
"initial_vowel": [annotations["initial_vowel"]]})
predictions.append(loaded_gam.predict_proba(new_data)[0])
name_stats = {
"name": [name, annotate_name(name)['pronouncation']],
"model_predictions": predictions,
"name_characterization": characterize_name(annotations),
}
return jsonify(name_stats)
if __name__ == "__main__":
app.run()