abhishtomish commited on
Commit
fa34ba6
·
verified ·
1 Parent(s): a82af88

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +24 -67
  2. README.md +4 -4
  3. requirements.txt +11 -0
  4. server/Dockerfile +67 -24
  5. server/requirements.txt +1 -1
Dockerfile CHANGED
@@ -1,86 +1,43 @@
1
- # Copyright (c) Meta Platforms, Inc. and affiliates.
2
- # All rights reserved.
3
  #
4
- # This source code is licensed under the BSD-style license found in the
5
- # LICENSE file in the root directory of this source tree.
 
 
 
 
6
 
7
- # Multi-stage build using openenv-base
8
- # This Dockerfile is flexible and works for both:
9
- # - In-repo environments (with local OpenEnv sources)
10
- # - Standalone environments (with openenv from PyPI/Git)
11
- # The build script (openenv build) handles context detection and sets appropriate build args.
12
-
13
- ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
14
- FROM ${BASE_IMAGE} AS builder
15
 
16
  WORKDIR /app
17
 
18
- # Ensure git is available (required for installing dependencies from VCS)
19
- RUN apt-get update && \
20
- apt-get install -y --no-install-recommends git curl ffmpeg && \
21
- rm -rf /var/lib/apt/lists/*
22
-
23
- # Build argument to control whether we're building standalone or in-repo
24
- ARG BUILD_MODE=in-repo
25
- ARG ENV_NAME=ai_content_detector_env
26
-
27
- # Copy environment code (always at root of build context)
28
- COPY . /app/env
29
 
30
- # For in-repo builds, openenv is already vendored in the build context
31
- # For standalone builds, openenv will be installed via pyproject.toml
32
- WORKDIR /app/env
33
 
34
- # Ensure uv is available (for local builds where base image lacks it)
35
- RUN if ! command -v uv >/dev/null 2>&1; then \
36
- curl -LsSf https://astral.sh/uv/install.sh | sh && \
37
- mv /root/.local/bin/uv /usr/local/bin/uv && \
38
- mv /root/.local/bin/uvx /usr/local/bin/uvx; \
39
- fi
40
-
41
- # Install dependencies using uv sync
42
- # If uv.lock exists, use it; otherwise resolve on the fly
43
- RUN --mount=type=cache,target=/root/.cache/uv \
44
- if [ -f uv.lock ]; then \
45
- uv sync --frozen --no-install-project --no-editable; \
46
- else \
47
- uv sync --no-install-project --no-editable; \
48
- fi
49
 
50
- RUN --mount=type=cache,target=/root/.cache/uv \
51
- if [ -f uv.lock ]; then \
52
- uv sync --frozen --no-editable; \
53
- else \
54
- uv sync --no-editable; \
55
- fi
56
-
57
- # Final runtime stage
58
- FROM ${BASE_IMAGE}
59
-
60
- WORKDIR /app
61
 
62
- # Copy the virtual environment from builder
63
- COPY --from=builder /app/env/.venv /app/.venv
64
-
65
- # Copy the environment code
66
- COPY --from=builder /app/env /app/env
67
-
68
- # Set PATH to use the virtual environment
69
- ENV PATH="/app/.venv/bin:$PATH"
70
-
71
- # Set PYTHONPATH so imports work correctly
72
- ENV PYTHONPATH="/app/env:$PYTHONPATH"
73
-
74
- # Health check
75
  # Run as non-root user
76
  RUN useradd -m appuser && chown -R appuser /app
77
  USER appuser
78
 
 
 
79
  HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
80
  CMD curl -f http://localhost:7860/health || exit 1
81
 
82
  ENV PRELOAD=1
83
 
84
- # Run the FastAPI server on port 7860 (HuggingFace Spaces standard)
85
  ENV ENABLE_WEB_INTERFACE=true
86
- CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]
 
1
+ # AI Content Detector OpenEnv Environment
2
+ # HuggingFace Spaces deployment (port 7860)
3
  #
4
+ # Build: docker build -t ai-content-detector .
5
+ # Run: docker run -p 7860:7860 \
6
+ # -e API_BASE_URL=https://api-inference.huggingface.co/v1 \
7
+ # -e MODEL_NAME=meta-llama/Llama-3-8b-Instruct \
8
+ # -e HF_TOKEN=hf_... \
9
+ # ai-content-detector
10
 
11
+ FROM python:3.11-slim
 
 
 
 
 
 
 
12
 
13
  WORKDIR /app
14
 
15
+ # ffmpeg is required by imageio[ffmpeg] for video support
16
+ RUN apt-get update && apt-get install -y --no-install-recommends \
17
+ curl ca-certificates ffmpeg \
18
+ && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
19
 
20
+ COPY requirements.txt .
21
+ RUN pip install --no-cache-dir -r requirements.txt
 
22
 
23
+ COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ # Pre-download HC3 dataset at build time for faster cold start
26
+ # (comment out to keep image smaller; dataset downloads on first request)
27
+ RUN python -c "from dataset import load_samples; \
28
+ load_samples('easy'); load_samples('medium'); load_samples('hard')" \
29
+ || echo 'Dataset pre-load skipped (no internet at build time)'
 
 
 
 
 
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Run as non-root user
32
  RUN useradd -m appuser && chown -R appuser /app
33
  USER appuser
34
 
35
+ EXPOSE 7860
36
+
37
  HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
38
  CMD curl -f http://localhost:7860/health || exit 1
39
 
40
  ENV PRELOAD=1
41
 
 
42
  ENV ENABLE_WEB_INTERFACE=true
43
+ CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -5,10 +5,10 @@ colorFrom: blue
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
- app_port: 8000
9
- base_path: /web
10
  tags:
11
  - openenv
 
12
  ---
13
 
14
  # Ai Content Detector Env Environment
@@ -163,7 +163,7 @@ The client supports context manager usage for automatic connection management:
163
  from ai_content_detector_env import AiContentDetectorAction, AiContentDetectorEnv
164
 
165
  # Connect with context manager (auto-connects and closes)
166
- with AiContentDetectorEnv(base_url="http://localhost:8000") as env:
167
  result = env.reset()
168
  print(f"Reset: {result.observation.echoed_message}")
169
  # Multiple steps with low latency
@@ -199,7 +199,7 @@ from ai_content_detector_env import AiContentDetectorAction, AiContentDetectorEn
199
  from concurrent.futures import ThreadPoolExecutor
200
 
201
  def run_episode(client_id: int):
202
- with AiContentDetectorEnv(base_url="http://localhost:8000") as env:
203
  result = env.reset()
204
  for i in range(10):
205
  result = env.step(AiContentDetectorAction(message=f"Client {client_id}, step {i}"))
 
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
 
9
  tags:
10
  - openenv
11
+ base_path: /web
12
  ---
13
 
14
  # Ai Content Detector Env Environment
 
163
  from ai_content_detector_env import AiContentDetectorAction, AiContentDetectorEnv
164
 
165
  # Connect with context manager (auto-connects and closes)
166
+ with AiContentDetectorEnv(base_url="http://localhost:7860") as env:
167
  result = env.reset()
168
  print(f"Reset: {result.observation.echoed_message}")
169
  # Multiple steps with low latency
 
199
  from concurrent.futures import ThreadPoolExecutor
200
 
201
  def run_episode(client_id: int):
202
+ with AiContentDetectorEnv(base_url="http://localhost:7860") as env:
203
  result = env.reset()
204
  for i in range(10):
205
  result = env.step(AiContentDetectorAction(message=f"Client {client_id}, step {i}"))
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ openenv-core[core]>=0.2.2
2
+ fastapi>=0.115.0
3
+ uvicorn[standard]>=0.29.0
4
+ pydantic>=2.0.0
5
+ websockets>=12.0
6
+ python-multipart>=0.0.9
7
+ datasets>=2.18.0
8
+ openai>=1.20.0
9
+ Pillow>=10.0.0
10
+ imageio>=2.33.0
11
+ imageio[ffmpeg]>=2.33.0
server/Dockerfile CHANGED
@@ -1,42 +1,85 @@
1
- # AI Content Detector OpenEnv Environment
2
- # HuggingFace Spaces deployment (port 7860)
3
  #
4
- # Build: docker build -t ai-content-detector .
5
- # Run: docker run -p 7860:7860 \
6
- # -e API_BASE_URL=https://api-inference.huggingface.co/v1 \
7
- # -e MODEL_NAME=meta-llama/Llama-3-8b-Instruct \
8
- # -e HF_TOKEN=hf_... \
9
- # ai-content-detector
10
 
11
- FROM python:3.11-slim
 
 
 
 
 
 
 
12
 
13
  WORKDIR /app
14
 
15
- # ffmpeg is required by imageio[ffmpeg] for video support
16
- RUN apt-get update && apt-get install -y --no-install-recommends \
17
- curl ca-certificates ffmpeg \
18
- && rm -rf /var/lib/apt/lists/*
 
 
 
 
 
 
 
19
 
20
- COPY requirements.txt .
21
- RUN pip install --no-cache-dir -r requirements.txt
 
22
 
23
- COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # Pre-download HC3 dataset at build time for faster cold start
26
- # (comment out to keep image smaller; dataset downloads on first request)
27
- RUN python -c "from dataset import load_samples; \
28
- load_samples('easy'); load_samples('medium'); load_samples('hard')" \
29
- || echo 'Dataset pre-load skipped (no internet at build time)'
 
 
 
 
 
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Run as non-root user
32
  RUN useradd -m appuser && chown -R appuser /app
33
  USER appuser
34
 
35
- EXPOSE 7860
36
-
37
  HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
38
  CMD curl -f http://localhost:7860/health || exit 1
39
 
40
  ENV PRELOAD=1
41
 
42
- CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
  #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
 
 
 
 
6
 
7
+ # Multi-stage build using openenv-base
8
+ # This Dockerfile is flexible and works for both:
9
+ # - In-repo environments (with local OpenEnv sources)
10
+ # - Standalone environments (with openenv from PyPI/Git)
11
+ # The build script (openenv build) handles context detection and sets appropriate build args.
12
+
13
+ ARG BASE_IMAGE=ghcr.io/meta-pytorch/openenv-base:latest
14
+ FROM ${BASE_IMAGE} AS builder
15
 
16
  WORKDIR /app
17
 
18
+ # Ensure git is available (required for installing dependencies from VCS)
19
+ RUN apt-get update && \
20
+ apt-get install -y --no-install-recommends git curl ffmpeg && \
21
+ rm -rf /var/lib/apt/lists/*
22
+
23
+ # Build argument to control whether we're building standalone or in-repo
24
+ ARG BUILD_MODE=in-repo
25
+ ARG ENV_NAME=ai_content_detector_env
26
+
27
+ # Copy environment code (always at root of build context)
28
+ COPY . /app/env
29
 
30
+ # For in-repo builds, openenv is already vendored in the build context
31
+ # For standalone builds, openenv will be installed via pyproject.toml
32
+ WORKDIR /app/env
33
 
34
+ # Ensure uv is available (for local builds where base image lacks it)
35
+ RUN if ! command -v uv >/dev/null 2>&1; then \
36
+ curl -LsSf https://astral.sh/uv/install.sh | sh && \
37
+ mv /root/.local/bin/uv /usr/local/bin/uv && \
38
+ mv /root/.local/bin/uvx /usr/local/bin/uvx; \
39
+ fi
40
+
41
+ # Install dependencies using uv sync
42
+ # If uv.lock exists, use it; otherwise resolve on the fly
43
+ RUN --mount=type=cache,target=/root/.cache/uv \
44
+ if [ -f uv.lock ]; then \
45
+ uv sync --frozen --no-install-project --no-editable; \
46
+ else \
47
+ uv sync --no-install-project --no-editable; \
48
+ fi
49
 
50
+ RUN --mount=type=cache,target=/root/.cache/uv \
51
+ if [ -f uv.lock ]; then \
52
+ uv sync --frozen --no-editable; \
53
+ else \
54
+ uv sync --no-editable; \
55
+ fi
56
+
57
+ # Final runtime stage
58
+ FROM ${BASE_IMAGE}
59
+
60
+ WORKDIR /app
61
 
62
+ # Copy the virtual environment from builder
63
+ COPY --from=builder /app/env/.venv /app/.venv
64
+
65
+ # Copy the environment code
66
+ COPY --from=builder /app/env /app/env
67
+
68
+ # Set PATH to use the virtual environment
69
+ ENV PATH="/app/.venv/bin:$PATH"
70
+
71
+ # Set PYTHONPATH so imports work correctly
72
+ ENV PYTHONPATH="/app/env:$PYTHONPATH"
73
+
74
+ # Health check
75
  # Run as non-root user
76
  RUN useradd -m appuser && chown -R appuser /app
77
  USER appuser
78
 
 
 
79
  HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
80
  CMD curl -f http://localhost:7860/health || exit 1
81
 
82
  ENV PRELOAD=1
83
 
84
+ # Run the FastAPI server on port 7860 (HuggingFace Spaces standard)
85
+ CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]
server/requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- openenv[core]>=0.2.0
2
  fastapi>=0.115.0
3
  uvicorn[standard]>=0.29.0
4
  pydantic>=2.0.0
 
1
+ openenv-core[core]>=0.2.2
2
  fastapi>=0.115.0
3
  uvicorn[standard]>=0.29.0
4
  pydantic>=2.0.0