File size: 888 Bytes
870b562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import logging

from flask import Flask, request, jsonify

from final import Translator

app = Flask(_name_)

model_path = 'model.h5'  

model = Translator(model_path)
logging.basicConfig(level=logging.INFO)

@app.route("/")
def index():
    """Provide a simple health check route."""
    return "Hello world!"

@app.route("/v1/predict", methods=["GET", "POST"])
def predict():
    """Provide the main prediction API route. Responds to both GET and POST requests."""
    logging.info("Predict request received!")
    question_text = request.args.get("question_text") 
    predicted_answer = model.predict(question_text)
    
    logging.info("Predicted answer: {}".format(predicted_answer))
    return jsonify({"predicted_answer": predicted_answer})

def main():
    """Run the Flask app."""
    app.run(host="0.0.0.0", port=8000, debug=False)

if _name_ == "_main_":
    main()