GDMProjects commited on
Commit
fc02943
·
verified ·
1 Parent(s): 58ebf5f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -36
Dockerfile CHANGED
@@ -1,41 +1,34 @@
 
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", "GDMProjects/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"]
 
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"]