|
import os |
|
from flask import Flask, request, jsonify |
|
from dotenv import load_dotenv |
|
import requests |
|
|
|
load_dotenv() |
|
api_key = os.getenv('HF_API_KEY') |
|
model_path = os.getenv('MODEL_PATH') |
|
|
|
app = Flask(__name__) |
|
|
|
def get_model_predictions(text): |
|
headers = {"Authorization": f"Bearer {api_key}"} |
|
payload = {"inputs": text} |
|
response = requests.post(f"https://api.huggingface.co/models/{model_path}", headers=headers, json=payload) |
|
return response.json() |
|
|
|
@app.route('/predict', methods=['POST']) |
|
def predict(): |
|
data = request.get_json() |
|
text = data['text'] |
|
prediction = get_model_predictions(text) |
|
return jsonify(prediction) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |