Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +10 -4
- app.py +25 -7
Dockerfile
CHANGED
|
@@ -11,9 +11,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 11 |
# Create non-root user for security (HF Spaces best practice)
|
| 12 |
RUN useradd -m -u 1000 user
|
| 13 |
|
| 14 |
-
# Switch to non-root user
|
| 15 |
-
USER user
|
| 16 |
-
|
| 17 |
# Set user environment variables
|
| 18 |
ENV HOME=/home/user \
|
| 19 |
PATH=/home/user/.local/bin:$PATH
|
|
@@ -24,13 +21,22 @@ WORKDIR $HOME/app
|
|
| 24 |
# Copy application files with correct ownership
|
| 25 |
COPY --chown=user . $HOME/app
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
# Expose Hugging Face Spaces standard port
|
| 28 |
EXPOSE 7860
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Run Streamlit on port 7860 with production settings
|
| 31 |
CMD ["streamlit", "run", "app.py", \
|
| 32 |
"--server.port=7860", \
|
| 33 |
"--server.address=0.0.0.0", \
|
| 34 |
"--server.headless=true", \
|
| 35 |
"--server.fileWatcherType=none", \
|
| 36 |
-
"--browser.gatherUsageStats=false"
|
|
|
|
|
|
|
|
|
| 11 |
# Create non-root user for security (HF Spaces best practice)
|
| 12 |
RUN useradd -m -u 1000 user
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
# Set user environment variables
|
| 15 |
ENV HOME=/home/user \
|
| 16 |
PATH=/home/user/.local/bin:$PATH
|
|
|
|
| 21 |
# Copy application files with correct ownership
|
| 22 |
COPY --chown=user . $HOME/app
|
| 23 |
|
| 24 |
+
# Switch to non-root user
|
| 25 |
+
USER user
|
| 26 |
+
|
| 27 |
# Expose Hugging Face Spaces standard port
|
| 28 |
EXPOSE 7860
|
| 29 |
|
| 30 |
+
# Health check for container monitoring
|
| 31 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 32 |
+
CMD curl --fail http://localhost:7860/_stcore/health || exit 1
|
| 33 |
+
|
| 34 |
# Run Streamlit on port 7860 with production settings
|
| 35 |
CMD ["streamlit", "run", "app.py", \
|
| 36 |
"--server.port=7860", \
|
| 37 |
"--server.address=0.0.0.0", \
|
| 38 |
"--server.headless=true", \
|
| 39 |
"--server.fileWatcherType=none", \
|
| 40 |
+
"--browser.gatherUsageStats=false", \
|
| 41 |
+
"--server.enableCORS=false", \
|
| 42 |
+
"--server.enableXsrfProtection=false"]
|
app.py
CHANGED
|
@@ -33,6 +33,17 @@ except Exception as e:
|
|
| 33 |
st.error(f"Import failed: {e}")
|
| 34 |
st.stop()
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Custom CSS
|
| 37 |
st.markdown("""
|
| 38 |
<style>
|
|
@@ -113,6 +124,11 @@ def load_model():
|
|
| 113 |
print("Loading model into memory...", file=sys.stderr)
|
| 114 |
model = joblib.load(model_path)
|
| 115 |
print("✓ Model loaded successfully", file=sys.stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
print("=" * 70 + "\n", file=sys.stderr)
|
| 117 |
|
| 118 |
return model, None
|
|
@@ -272,18 +288,20 @@ def main():
|
|
| 272 |
st.markdown("---")
|
| 273 |
|
| 274 |
if st.button("🔍 Predict Engine Condition", use_container_width=True, type="primary"):
|
| 275 |
-
#
|
| 276 |
input_df = pd.DataFrame([{
|
| 277 |
-
"Engine rpm": engine_rpm,
|
| 278 |
-
"Lub oil pressure": lub_oil_pressure,
|
| 279 |
-
"Fuel pressure": fuel_pressure,
|
| 280 |
-
"Coolant pressure": coolant_pressure,
|
| 281 |
-
"lub oil temp": lub_oil_temp,
|
| 282 |
-
"Coolant temp": coolant_temp
|
| 283 |
}])
|
| 284 |
|
| 285 |
try:
|
| 286 |
print(f"Making prediction with input: {input_df.to_dict()}", file=sys.stderr)
|
|
|
|
|
|
|
| 287 |
|
| 288 |
# Make prediction
|
| 289 |
prediction = model.predict(input_df)[0]
|
|
|
|
| 33 |
st.error(f"Import failed: {e}")
|
| 34 |
st.stop()
|
| 35 |
|
| 36 |
+
# CRITICAL: Feature columns must EXACTLY match model training
|
| 37 |
+
# These are from model_prep.py FEATURE_COLUMNS
|
| 38 |
+
FEATURE_COLUMNS = [
|
| 39 |
+
"Engine rpm",
|
| 40 |
+
"Lub oil pressure",
|
| 41 |
+
"Fuel pressure",
|
| 42 |
+
"Coolant pressure",
|
| 43 |
+
"lub oil temp",
|
| 44 |
+
"Coolant temp"
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
# Custom CSS
|
| 48 |
st.markdown("""
|
| 49 |
<style>
|
|
|
|
| 124 |
print("Loading model into memory...", file=sys.stderr)
|
| 125 |
model = joblib.load(model_path)
|
| 126 |
print("✓ Model loaded successfully", file=sys.stderr)
|
| 127 |
+
|
| 128 |
+
# Verify model features
|
| 129 |
+
if hasattr(model, 'feature_names_in_'):
|
| 130 |
+
print(f"Model expects features: {model.feature_names_in_}", file=sys.stderr)
|
| 131 |
+
|
| 132 |
print("=" * 70 + "\n", file=sys.stderr)
|
| 133 |
|
| 134 |
return model, None
|
|
|
|
| 288 |
st.markdown("---")
|
| 289 |
|
| 290 |
if st.button("🔍 Predict Engine Condition", use_container_width=True, type="primary"):
|
| 291 |
+
# CRITICAL FIX: Use exact column names that match model training
|
| 292 |
input_df = pd.DataFrame([{
|
| 293 |
+
"Engine rpm": engine_rpm, # Lowercase 'rpm'
|
| 294 |
+
"Lub oil pressure": lub_oil_pressure, # Lowercase 'oil'
|
| 295 |
+
"Fuel pressure": fuel_pressure, # Lowercase 'pressure'
|
| 296 |
+
"Coolant pressure": coolant_pressure, # Lowercase 'pressure'
|
| 297 |
+
"lub oil temp": lub_oil_temp, # All lowercase
|
| 298 |
+
"Coolant temp": coolant_temp # Lowercase 'temp'
|
| 299 |
}])
|
| 300 |
|
| 301 |
try:
|
| 302 |
print(f"Making prediction with input: {input_df.to_dict()}", file=sys.stderr)
|
| 303 |
+
print(f"Input columns: {input_df.columns.tolist()}", file=sys.stderr)
|
| 304 |
+
print(f"Expected columns: {FEATURE_COLUMNS}", file=sys.stderr)
|
| 305 |
|
| 306 |
# Make prediction
|
| 307 |
prediction = model.predict(input_df)[0]
|