File size: 965 Bytes
8516514
 
 
 
 
7d1002c
8516514
 
 
 
 
 
 
 
 
9c1f8b0
 
 
 
 
 
 
 
8516514
 
 
 
 
 
 
7d1002c
 
 
9c1f8b0
 
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
31
32
33
34
35
36
from flask import Flask, request, jsonify
from flask_cors import CORS
from inference import InferenceModel
import traceback

app = Flask(__name__)
CORS(app)

try:
    model = InferenceModel(path_to_weights="save_model/model.safetensors", huggingface_model=True)
except Exception as e:
    print("❌ Lỗi khi load mô hình:")
    traceback.print_exc()
    model = None

@app.route("/")
def home():
    return "Space is alive!", 200

@app.route("/health")
def health():
    return "Healthy", 200

@app.route('/pred', methods=['POST'])
def prediction():
    payload = request.get_json()
    context = payload.get('context', '')
    question = payload.get('question', '')
    prediction = model.inference_model(question, context)
    answer = prediction["answer"]
    return jsonify({"answer": answer}), 200

if __name__ == '__main__':
    # Cực kỳ quan trọng: host=0.0.0.0 để Hugging Face gọi được
    app.run(host="0.0.0.0", port=7860, debug=False)