Spaces:
Running
Running
AsamiYukiko Claude Sonnet 4.6 commited on
Commit ·
a07581b
1
Parent(s): 30e6c9e
refactor: replace tutorial-style messages with production-grade log output
Browse files- app.py: startup prints now use [INFO]/[ERROR] prefixes; HTTP 500 error
message changed from instructional text to a concise service-status string
- Dockerfile: removed platform-specific annotation comments, replaced with
neutral infrastructure rationale
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dockerfile +2 -2
- app.py +3 -3
Dockerfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# PV Defect Classifier — HuggingFace Spaces
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
RUN useradd -m -u 1000 user
|
| 6 |
|
| 7 |
WORKDIR /app
|
|
@@ -22,6 +22,6 @@ USER user
|
|
| 22 |
ENV HOME=/home/user \
|
| 23 |
PATH=/home/user/.local/bin:$PATH
|
| 24 |
|
| 25 |
-
#
|
| 26 |
# 1 worker = 1 model copy in memory; timeout 120s for cold start
|
| 27 |
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "120", "app:app"]
|
|
|
|
| 1 |
# PV Defect Classifier — HuggingFace Spaces
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# Run as non-root user (UID 1000) per container security best practices
|
| 5 |
RUN useradd -m -u 1000 user
|
| 6 |
|
| 7 |
WORKDIR /app
|
|
|
|
| 22 |
ENV HOME=/home/user \
|
| 23 |
PATH=/home/user/.local/bin:$PATH
|
| 24 |
|
| 25 |
+
# Bind to container-configured application port 7860
|
| 26 |
# 1 worker = 1 model copy in memory; timeout 120s for cold start
|
| 27 |
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "120", "app:app"]
|
app.py
CHANGED
|
@@ -33,10 +33,10 @@ model_path = find_onnx_model()
|
|
| 33 |
if model_path:
|
| 34 |
session = ort.InferenceSession(model_path)
|
| 35 |
input_name = session.get_inputs()[0].name
|
| 36 |
-
print(f"
|
| 37 |
else:
|
| 38 |
session = None
|
| 39 |
-
print(" No
|
| 40 |
|
| 41 |
|
| 42 |
# Preprocessing
|
|
@@ -64,7 +64,7 @@ def index():
|
|
| 64 |
@app.route("/predict", methods=["POST"])
|
| 65 |
def predict():
|
| 66 |
if session is None:
|
| 67 |
-
return jsonify({"error": "
|
| 68 |
|
| 69 |
if "file" not in request.files:
|
| 70 |
return jsonify({"error": "No file uploaded."}), 400
|
|
|
|
| 33 |
if model_path:
|
| 34 |
session = ort.InferenceSession(model_path)
|
| 35 |
input_name = session.get_inputs()[0].name
|
| 36 |
+
print(f"[INFO] Model loaded: {os.path.basename(model_path)}")
|
| 37 |
else:
|
| 38 |
session = None
|
| 39 |
+
print("[ERROR] No ONNX model file found in MODEL_DIR. Inference endpoint will be unavailable.")
|
| 40 |
|
| 41 |
|
| 42 |
# Preprocessing
|
|
|
|
| 64 |
@app.route("/predict", methods=["POST"])
|
| 65 |
def predict():
|
| 66 |
if session is None:
|
| 67 |
+
return jsonify({"error": "Inference service unavailable: model not loaded."}), 500
|
| 68 |
|
| 69 |
if "file" not in request.files:
|
| 70 |
return jsonify({"error": "No file uploaded."}), 400
|