TangSan003's picture
Update app.py
9c1f8b0 verified
raw
history blame contribute delete
965 Bytes
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)