|
from flask import Flask, request, jsonify |
|
import tensorflow as tf |
|
import numpy as np |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
interpreter = tf.lite.Interpreter(model_path="quote_model.tflite") |
|
interpreter.allocate_tensors() |
|
|
|
|
|
input_details = interpreter.get_input_details() |
|
output_details = interpreter.get_output_details() |
|
|
|
@app.route("/predict", methods=["POST"]) |
|
def predict(): |
|
try: |
|
data = request.json |
|
embedding = np.array([data["embedding"]], dtype=np.float32) |
|
|
|
|
|
interpreter.set_tensor(input_details[0]['index'], embedding) |
|
interpreter.invoke() |
|
output_data = interpreter.get_tensor(output_details[0]['index']) |
|
|
|
return jsonify({"predictions": output_data.tolist()}) |
|
|
|
except Exception as e: |
|
return jsonify({"error": str(e)}) |
|
|
|
|
|
if __name__ == "__main__": |
|
app.run(host="0.0.0.0", port=7860) |
|
|