Update app.py
Browse files
app.py
CHANGED
|
@@ -7,10 +7,10 @@ import torch
|
|
| 7 |
from huggingface_hub import login
|
| 8 |
|
| 9 |
# Cấu hình logging
|
| 10 |
-
logging.basicConfig(level=logging.INFO)
|
| 11 |
|
| 12 |
# Đăng nhập Hugging Face
|
| 13 |
-
login(token="
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
|
|
@@ -28,10 +28,12 @@ def answer():
|
|
| 28 |
data = request.json
|
| 29 |
question = data.get("question")
|
| 30 |
context = data.get("context")
|
|
|
|
| 31 |
if not question or not context:
|
|
|
|
| 32 |
return jsonify({"error": "Missing question or context"}), 400
|
| 33 |
result = qa_pipeline(question=question, context=context)
|
| 34 |
-
logging.info(f"
|
| 35 |
return jsonify({"answer": result["answer"]})
|
| 36 |
except Exception as e:
|
| 37 |
logging.error(f"API error: {e}")
|
|
|
|
| 7 |
from huggingface_hub import login
|
| 8 |
|
| 9 |
# Cấu hình logging
|
| 10 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 11 |
|
| 12 |
# Đăng nhập Hugging Face
|
| 13 |
+
login(token=os.getenv("HF_TOKEN")) # Lấy token từ biến môi trường
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
|
|
|
|
| 28 |
data = request.json
|
| 29 |
question = data.get("question")
|
| 30 |
context = data.get("context")
|
| 31 |
+
logging.info(f"Received request - Question: {question}, Context: {context[:200]}...")
|
| 32 |
if not question or not context:
|
| 33 |
+
logging.error("Missing question or context")
|
| 34 |
return jsonify({"error": "Missing question or context"}), 400
|
| 35 |
result = qa_pipeline(question=question, context=context)
|
| 36 |
+
logging.info(f"Response - Answer: {result['answer']}")
|
| 37 |
return jsonify({"answer": result["answer"]})
|
| 38 |
except Exception as e:
|
| 39 |
logging.error(f"API error: {e}")
|