amitlals
commited on
Commit
·
9be8645
1
Parent(s):
c4ab29b
Simplify Dockerfile and add HF token authentication for gated model access
Browse files- Dockerfile +15 -38
- app_gradio.py +17 -0
Dockerfile
CHANGED
|
@@ -1,32 +1,6 @@
|
|
| 1 |
# Dockerfile for SAP Finance Dashboard with RPT-1-OSS Model
|
| 2 |
-
#
|
| 3 |
|
| 4 |
-
# Stage 1: Build wheels for heavy dependencies
|
| 5 |
-
FROM python:3.11-slim as builder
|
| 6 |
-
|
| 7 |
-
WORKDIR /wheels
|
| 8 |
-
|
| 9 |
-
# Install build dependencies
|
| 10 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 11 |
-
build-essential \
|
| 12 |
-
git \
|
| 13 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
-
|
| 15 |
-
# Create wheels directory for pip to use
|
| 16 |
-
RUN mkdir -p /wheels
|
| 17 |
-
|
| 18 |
-
# Build torch and other ML libraries as wheels (lighter than full install)
|
| 19 |
-
RUN pip wheel --no-cache-dir --wheel-dir=/wheels \
|
| 20 |
-
torch==2.0.0 \
|
| 21 |
-
torchvision==0.15.0 \
|
| 22 |
-
torchaudio==2.0.0 \
|
| 23 |
-
transformers==4.30.0 2>&1 || true
|
| 24 |
-
|
| 25 |
-
# Build other dependencies as wheels
|
| 26 |
-
RUN pip wheel --no-cache-dir --wheel-dir=/wheels \
|
| 27 |
-
git+https://github.com/SAP-samples/sap-rpt-1-oss 2>&1 || true
|
| 28 |
-
|
| 29 |
-
# Stage 2: Runtime image (minimal size)
|
| 30 |
FROM python:3.11-slim
|
| 31 |
|
| 32 |
# Set environment variables
|
|
@@ -35,11 +9,13 @@ ENV PYTHONUNBUFFERED=1
|
|
| 35 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 36 |
ENV GRADIO_SERVER_PORT=7860
|
| 37 |
ENV TORCH_HOME=/app/torch_cache
|
|
|
|
| 38 |
|
| 39 |
# Install minimal system dependencies
|
| 40 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 41 |
git \
|
| 42 |
curl \
|
|
|
|
| 43 |
&& rm -rf /var/lib/apt/lists/*
|
| 44 |
|
| 45 |
WORKDIR /app
|
|
@@ -48,27 +24,28 @@ WORKDIR /app
|
|
| 48 |
COPY requirements.txt .
|
| 49 |
|
| 50 |
# Install base dependencies
|
| 51 |
-
RUN pip install --no-cache-dir --upgrade pip && \
|
| 52 |
pip install --no-cache-dir -r requirements.txt
|
| 53 |
|
| 54 |
-
# Install
|
| 55 |
RUN pip install --no-cache-dir "gradio==4.44.1"
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
RUN pip install --no-cache-dir --no-index --find-links=/wheels \
|
| 60 |
torch==2.0.0 \
|
| 61 |
-
transformers==4.30.0
|
| 62 |
-
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Copy application code
|
| 68 |
COPY . .
|
| 69 |
|
| 70 |
-
# Create
|
| 71 |
-
RUN mkdir -p /app/data /app/torch_cache
|
| 72 |
|
| 73 |
# Expose port
|
| 74 |
EXPOSE 7860
|
|
|
|
| 1 |
# Dockerfile for SAP Finance Dashboard with RPT-1-OSS Model
|
| 2 |
+
# Optimized single-stage build for HuggingFace Spaces
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
FROM python:3.11-slim
|
| 5 |
|
| 6 |
# Set environment variables
|
|
|
|
| 9 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 10 |
ENV GRADIO_SERVER_PORT=7860
|
| 11 |
ENV TORCH_HOME=/app/torch_cache
|
| 12 |
+
ENV HUGGINGFACE_HUB_CACHE=/app/hf_cache
|
| 13 |
|
| 14 |
# Install minimal system dependencies
|
| 15 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
git \
|
| 17 |
curl \
|
| 18 |
+
build-essential \
|
| 19 |
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
|
| 21 |
WORKDIR /app
|
|
|
|
| 24 |
COPY requirements.txt .
|
| 25 |
|
| 26 |
# Install base dependencies
|
| 27 |
+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 28 |
pip install --no-cache-dir -r requirements.txt
|
| 29 |
|
| 30 |
+
# Install Gradio (pinned for stability)
|
| 31 |
RUN pip install --no-cache-dir "gradio==4.44.1"
|
| 32 |
|
| 33 |
+
# Install core ML libraries (pre-built wheels, no compilation needed)
|
| 34 |
+
RUN pip install --no-cache-dir \
|
|
|
|
| 35 |
torch==2.0.0 \
|
| 36 |
+
transformers==4.30.0 \
|
| 37 |
+
scikit-learn==1.2.0
|
| 38 |
|
| 39 |
+
# Install SAP-RPT-1-OSS from GitHub
|
| 40 |
+
# Note: Requires HF_TOKEN environment variable for gated model access
|
| 41 |
+
RUN pip install --no-cache-dir \
|
| 42 |
+
git+https://github.com/SAP-samples/sap-rpt-1-oss
|
| 43 |
|
| 44 |
# Copy application code
|
| 45 |
COPY . .
|
| 46 |
|
| 47 |
+
# Create required directories
|
| 48 |
+
RUN mkdir -p /app/data /app/torch_cache /app/hf_cache
|
| 49 |
|
| 50 |
# Expose port
|
| 51 |
EXPOSE 7860
|
app_gradio.py
CHANGED
|
@@ -74,6 +74,23 @@ def _patch_gradio_client_schema_bug():
|
|
| 74 |
_ensure_hf_folder_compat()
|
| 75 |
_patch_gradio_client_schema_bug()
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
import gradio as gr
|
| 78 |
print(f"Gradio version: {gr.__version__}")
|
| 79 |
import pandas as pd
|
|
|
|
| 74 |
_ensure_hf_folder_compat()
|
| 75 |
_patch_gradio_client_schema_bug()
|
| 76 |
|
| 77 |
+
# Setup HuggingFace authentication for gated model access
|
| 78 |
+
def _setup_hf_auth():
|
| 79 |
+
"""Authenticate with HuggingFace Hub using token from environment."""
|
| 80 |
+
try:
|
| 81 |
+
from huggingface_hub import login
|
| 82 |
+
|
| 83 |
+
hf_token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
|
| 84 |
+
if hf_token:
|
| 85 |
+
login(token=hf_token, add_to_git_credential=False)
|
| 86 |
+
print("✓ HuggingFace authentication configured")
|
| 87 |
+
else:
|
| 88 |
+
print("⚠ HF_TOKEN not found. Gated model access will fail if not already cached.")
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"⚠ HuggingFace auth setup failed: {e}")
|
| 91 |
+
|
| 92 |
+
_setup_hf_auth()
|
| 93 |
+
|
| 94 |
import gradio as gr
|
| 95 |
print(f"Gradio version: {gr.__version__}")
|
| 96 |
import pandas as pd
|