Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +29 -36
Dockerfile
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
| 4 |
COPY requirements.txt .
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
TOKEN = os.getenv("HF_TOKEN")
|
| 20 |
-
|
| 21 |
-
local_path = hf_hub_download(repo_id=REPO, filename=FNAME, token=TOKEN)
|
| 22 |
-
model = load_model(local_path)
|
| 23 |
-
|
| 24 |
-
def infer(csv_text):
|
| 25 |
-
df = pd.read_csv(pd.compat.StringIO(csv_text)) if "," in csv_text else pd.read_csv(csv_text)
|
| 26 |
-
out = predict_model(model, data=df)
|
| 27 |
-
return out.to_csv(index=False)
|
| 28 |
-
|
| 29 |
-
demo = gr.Interface(fn=infer, inputs=gr.Textbox(lines=8, label="CSV (paste) or path"),
|
| 30 |
-
outputs=gr.Textbox(label="Predictions CSV"))
|
| 31 |
-
if __name__ == "__main__":
|
| 32 |
-
import os
|
| 33 |
-
port = int(os.getenv("PORT", "7860"))
|
| 34 |
-
demo.launch(server_name="0.0.0.0", server_port=port)
|
| 35 |
-
"""
|
| 36 |
-
pathlib.Path("app.py").write_text(textwrap.dedent(code), encoding="utf-8")
|
| 37 |
-
PY
|
| 38 |
-
|
| 39 |
-
ENV GRADIO_SERVER_NAME=0.0.0.0 MPLCONFIGDIR=/tmp/matplotlib PYTHONUNBUFFERED=1
|
| 40 |
EXPOSE 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
+
# Base
|
| 2 |
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# System deps for LightGBM (OpenMP)
|
| 5 |
+
RUN apt-get update \
|
| 6 |
+
&& apt-get install -y --no-install-recommends libgomp1 \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
# App workdir
|
| 10 |
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# Copy files first (owned by root initially)
|
| 13 |
+
COPY app.py .
|
| 14 |
COPY requirements.txt .
|
| 15 |
+
COPY subset_best_model.pkl .
|
| 16 |
+
COPY GTT.csv .
|
| 17 |
+
|
| 18 |
+
# Install Python deps
|
| 19 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 20 |
+
|
| 21 |
+
# Make /app writable for the runtime user to avoid PyCaret logging warnings
|
| 22 |
+
# (Hugging Face Spaces often runs as a non-root user)
|
| 23 |
+
RUN chmod -R a+rw /app
|
| 24 |
+
|
| 25 |
+
# Optional: pre-create a writable log file to silence the warning completely
|
| 26 |
+
RUN touch /app/logs.log && chmod 666 /app/logs.log
|
| 27 |
+
|
| 28 |
+
# Gradio / Matplotlib envs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
EXPOSE 7860
|
| 30 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 31 |
+
ENV MPLCONFIGDIR=/tmp/matplotlib
|
| 32 |
+
ENV PYTHONUNBUFFERED=1
|
| 33 |
+
|
| 34 |
CMD ["python", "app.py"]
|