-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
35 lines (24 loc) · 962 Bytes
/
server.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
from flask import Flask, Response
from prediction import predict
from flask_sslify import SSLify
import tensorflow as tf
from transformers import TFAutoModel, AutoTokenizer
import pandas as pd
import numpy as np
checkpoint_path = "checkpoint/"
model = tf.keras.models.load_model(checkpoint_path)
predictions, raw_outputs = model.predict(["Sam was a Wizard"])
server = Flask(__name__)
sslify = SSLify(server)
@server.route("/")
def hello():
return 'Title clickbait API'
@server.route("/<title>")
def api(title):
result, test_sequences, test_padded_titles = predict(model, title, tokenizer, pad_sequences, max_length)
resp = Response(str(result))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
if __name__ == "__main__":
context = ('basile-bron.fr_2021-02-19.crt', 'basile-bron.fr_2021-02-19.key') # certificate and key files
server.run(host='0.0.0.0', ssl_context=context)