File size: 542 Bytes
634cec7 5cf5335 16ede2d 5cf5335 16ede2d 5cf5335 16ede2d 5cf5335 16ede2d 5cf5335 16ede2d 5cf5335 |
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 |
import os
from flask import Flask, request, jsonify
from dotenv import load_dotenv
import tensorflow as tf
load_dotenv()
api_key = os.getenv('HF_API_KEY')
model_path = os.getenv('MODEL_PATH')
app = Flask(__name__)
def load_model():
return tf.keras.models.load_model(model_path)
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json()
text = data['text']
model = load_model()
prediction = model.predict([text])
return jsonify(prediction.tolist())
if __name__ == '__main__':
app.run()
|