Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +36 -29
Dockerfile
CHANGED
|
@@ -1,34 +1,41 @@
|
|
| 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 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"]
|
|
|
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends libgomp1 && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
| 4 |
COPY requirements.txt .
|
| 5 |
+
RUN pip install --no-cache-dir -r requirements.txt && pip install --no-cache-dir huggingface_hub
|
| 6 |
+
|
| 7 |
+
# Generate app.py during build so it's not in the repo
|
| 8 |
+
RUN python - <<'PY'
|
| 9 |
+
import textwrap, pathlib
|
| 10 |
+
code = """
|
| 11 |
+
import os
|
| 12 |
+
from huggingface_hub import hf_hub_download
|
| 13 |
+
from pycaret.classification import load_model, predict_model
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import pandas as pd
|
| 16 |
+
|
| 17 |
+
REPO = os.getenv("MODEL_REPO", "<USERNAME>/my-private-model")
|
| 18 |
+
FNAME = os.getenv("MODEL_FILE", "subset_best_model.pkl")
|
| 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"]
|