Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
from flask import Flask, request, jsonify
|
3 |
from dotenv import load_dotenv
|
4 |
-
import
|
5 |
|
6 |
load_dotenv()
|
7 |
api_key = os.getenv('HF_API_KEY')
|
@@ -9,16 +9,18 @@ model_path = os.getenv('MODEL_PATH')
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
-
def
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
@app.route('/predict', methods=['POST'])
|
16 |
def predict():
|
17 |
data = request.get_json()
|
18 |
text = data['text']
|
19 |
-
|
20 |
-
|
21 |
-
return jsonify(prediction.tolist())
|
22 |
|
23 |
if __name__ == '__main__':
|
24 |
-
app.run()
|
|
|
1 |
import os
|
2 |
from flask import Flask, request, jsonify
|
3 |
from dotenv import load_dotenv
|
4 |
+
import requests
|
5 |
|
6 |
load_dotenv()
|
7 |
api_key = os.getenv('HF_API_KEY')
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
+
def get_model_predictions(text):
|
13 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
14 |
+
payload = {"inputs": text}
|
15 |
+
response = requests.post(f"https://api.huggingface.co/models/{model_path}", headers=headers, json=payload)
|
16 |
+
return response.json()
|
17 |
|
18 |
@app.route('/predict', methods=['POST'])
|
19 |
def predict():
|
20 |
data = request.get_json()
|
21 |
text = data['text']
|
22 |
+
prediction = get_model_predictions(text)
|
23 |
+
return jsonify(prediction)
|
|
|
24 |
|
25 |
if __name__ == '__main__':
|
26 |
+
app.run(debug=True)
|