Spaces:
Sleeping
Sleeping
File size: 780 Bytes
dc480fb d38e396 f51ee25 732d546 d38e396 732d546 d38e396 dc480fb f51ee25 d38e396 f51ee25 dc480fb d38e396 f51ee25 |
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 |
import os
from dotenv import load_dotenv
from flask import Flask, request, jsonify
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)
@app.route('/', methods=['GET'])
def index():
return "Welcome to My AI!"
if __name__ == '__main__':
app.run(debug=True) |