Spaces:
Sleeping
Sleeping
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 | |
def home(): | |
return "Space is alive!", 200 | |
def health(): | |
return "Healthy", 200 | |
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) | |