quotes / app.py
chandugeesala0's picture
Create app.py
a17d371 verified
from flask import Flask, request, jsonify
import tensorflow as tf
import numpy as np
app = Flask(__name__)
# Load the TensorFlow Lite model
interpreter = tf.lite.Interpreter(model_path="quote_model.tflite") # Use your model file name
interpreter.allocate_tensors()
# Get input & output details
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
@app.route("/predict", methods=["POST"])
def predict():
try:
data = request.json # Get input JSON
embedding = np.array([data["embedding"]], dtype=np.float32) # Convert to tensor
# Run inference
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)})
# Run the Flask server
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)