Aryan commited on
Commit
482b9c0
·
1 Parent(s): d4cfa03

Restructure repository as OpenEnv standard API server

Browse files
Files changed (7) hide show
  1. Dockerfile +15 -5
  2. pyproject.toml +14 -0
  3. requirements.txt +0 -5
  4. server.log +18 -0
  5. server/app.py +21 -0
  6. uv.lock +0 -0
  7. validate-submission.sh +159 -0
Dockerfile CHANGED
@@ -1,11 +1,21 @@
1
- FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
- COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
7
 
 
 
 
 
 
 
 
8
  COPY . .
9
 
10
- # Run inference wrapper which interacts with env.py
11
- CMD ["python", "inference.py"]
 
 
 
 
1
+ FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
5
+ # Install uv securely from the official image
6
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
7
 
8
+ # Copy dependency manifests
9
+ COPY pyproject.toml uv.lock ./
10
+
11
+ # Generate virtual environment and sync dependencies
12
+ RUN uv sync --frozen
13
+
14
+ # Copy the rest of the application
15
  COPY . .
16
 
17
+ # Expose Hugging Face's default web routing port
18
+ EXPOSE 7860
19
+
20
+ # Run the OpenEnv ASGI server entrypoint
21
+ CMD ["uv", "run", "server"]
pyproject.toml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "scheduling-benchmark"
3
+ version = "0.1.0"
4
+ description = "Scheduling Assistant"
5
+ dependencies = [
6
+ "pydantic",
7
+ "openenv-core>=0.2.0",
8
+ "python-dateutil",
9
+ "pytz",
10
+ "fastapi",
11
+ "uvicorn"
12
+ ]
13
+ [project.scripts]
14
+ server = "server.app:main"
requirements.txt DELETED
@@ -1,5 +0,0 @@
1
- pydantic
2
- openai
3
- python-dateutil
4
- pytz
5
- dotenv
 
 
 
 
 
 
server.log ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ nohup: ignoring input
2
+ warning: `VIRTUAL_ENV=.myenv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
3
+ warning: No `requires-python` value found in the workspace. Defaulting to `>=3.11`.
4
+ Downloading openai (1.1MiB)
5
+ Downloading brotli (1.4MiB)
6
+ Downloading pydantic-core (2.0MiB)
7
+ Downloading pygments (1.2MiB)
8
+ Downloading beartype (1.3MiB)
9
+ Downloading hf-xet (4.0MiB)
10
+ Downloading gradio (35.1MiB)
11
+ Downloading cryptography (4.3MiB)
12
+ Downloading numpy (16.1MiB)
13
+ Downloading pillow (6.8MiB)
14
+ Downloading pandas (10.7MiB)
15
+ Downloaded openai
16
+ Downloaded pygments
17
+ Downloaded beartype
18
+ Downloaded brotli
server/app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import uvicorn
3
+ from openenv.core import create_fastapi_app
4
+ from env import SchedulingEnv, Action, Observation
5
+
6
+ def make_env():
7
+ task_level = os.getenv("TASK_LEVEL", "medium")
8
+ return SchedulingEnv(task_level=task_level)
9
+
10
+ app = create_fastapi_app(
11
+ env=make_env,
12
+ action_cls=Action,
13
+ observation_cls=Observation
14
+ )
15
+
16
+ def main():
17
+ port = int(os.getenv("PORT", 7860))
18
+ uvicorn.run("server.app:app", host="0.0.0.0", port=port, log_level="info")
19
+
20
+ if __name__ == "__main__":
21
+ main()
uv.lock ADDED
The diff for this file is too large to render. See raw diff
 
validate-submission.sh ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -uo pipefail
3
+
4
+ DOCKER_BUILD_TIMEOUT=600
5
+ if [ -t 1 ]; then
6
+ RED='\033[0;31m'
7
+ GREEN='\033[0;32m'
8
+ YELLOW='\033[1;33m'
9
+ BOLD='\033[1m'
10
+ NC='\033[0m'
11
+ else
12
+ RED='' GREEN='' YELLOW='' BOLD='' NC=''
13
+ fi
14
+
15
+ run_with_timeout() {
16
+ local secs="$1"; shift
17
+ if command -v timeout &>/dev/null; then
18
+ timeout "$secs" "$@"
19
+ elif command -v gtimeout &>/dev/null; then
20
+ gtimeout "$secs" "$@"
21
+ else
22
+ "$@" &
23
+ local pid=$!
24
+ ( sleep "$secs" && kill "$pid" 2>/dev/null ) &
25
+ local watcher=$!
26
+ wait "$pid" 2>/dev/null
27
+ local rc=$?
28
+ kill "$watcher" 2>/dev/null
29
+ wait "$watcher" 2>/dev/null
30
+ return $rc
31
+ fi
32
+ }
33
+
34
+ portable_mktemp() {
35
+ local prefix="${1:-validate}"
36
+ # Ensure the temp file exists instead of failing quietly
37
+ mktemp "${TMPDIR:-/tmp}/${prefix}-XXXXXX"
38
+ }
39
+
40
+ CLEANUP_FILES=()
41
+ cleanup() { rm -f "${CLEANUP_FILES[@]+"${CLEANUP_FILES[@]}"}"; }
42
+ trap cleanup EXIT
43
+
44
+ PING_URL="${1:-}"
45
+ REPO_DIR="${2:-.}"
46
+
47
+ if [ -z "$PING_URL" ]; then
48
+ printf "Usage: %s <ping_url> [repo_dir]\n" "$0"
49
+ printf "\n"
50
+ printf " ping_url Your HuggingFace Space URL (e.g. https://your-space.hf.space)\n"
51
+ printf " repo_dir Path to your repo (default: current directory)\n"
52
+ exit 1
53
+ fi
54
+
55
+ if ! REPO_DIR="$(cd "$REPO_DIR" 2>/dev/null && pwd)"; then
56
+ printf "Error: directory '%s' not found\n" "${2:-.}"
57
+ exit 1
58
+ fi
59
+ PING_URL="${PING_URL%/}"
60
+ export PING_URL
61
+ PASS=0
62
+
63
+ log() { printf "[%s] %b\n" "$(date -u +%H:%M:%S)" "$*"; }
64
+ pass() { log "${GREEN}PASSED${NC} -- $1"; PASS=$((PASS + 1)); }
65
+ fail() { log "${RED}FAILED${NC} -- $1"; }
66
+ hint() { printf " ${YELLOW}Hint:${NC} %b\n" "$1"; }
67
+ stop_at() {
68
+ printf "\n"
69
+ printf "${RED}${BOLD}Validation stopped at %s.${NC} Fix the above before continuing.\n" "$1"
70
+ exit 1
71
+ }
72
+
73
+ printf "\n"
74
+ printf "${BOLD}========================================${NC}\n"
75
+ printf "${BOLD} OpenEnv Submission Validator${NC}\n"
76
+ printf "${BOLD}========================================${NC}\n"
77
+ log "Repo: $REPO_DIR"
78
+ log "Ping URL: $PING_URL"
79
+ printf "\n"
80
+
81
+ log "${BOLD}Step 1/3: Pinging HF Space${NC} ($PING_URL/reset) ..."
82
+
83
+ CURL_OUTPUT=$(portable_mktemp "validate-curl")
84
+ CLEANUP_FILES+=("$CURL_OUTPUT")
85
+ HTTP_CODE=$(curl -s -o "$CURL_OUTPUT" -w "%{http_code}" -X POST \
86
+ -H "Content-Type: application/json" -d '{}' \
87
+ "$PING_URL/reset" --max-time 30 2>"$CURL_OUTPUT" || printf "000")
88
+
89
+ if [ "$HTTP_CODE" = "200" ]; then
90
+ pass "HF Space is live and responds to /reset"
91
+ elif [ "$HTTP_CODE" = "000" ]; then
92
+ fail "HF Space not reachable (connection failed or timed out)"
93
+ hint "Check your network connection and that the Space is running."
94
+ hint "Try: curl -s -o /dev/null -w '%{http_code}' -X POST $PING_URL/reset"
95
+ stop_at "Step 1"
96
+ else
97
+ fail "HF Space /reset returned HTTP $HTTP_CODE (expected 200)"
98
+ hint "Make sure your Space is running and the URL is correct."
99
+ hint "Try opening $PING_URL in your browser first."
100
+ stop_at "Step 1"
101
+ fi
102
+
103
+ log "${BOLD}Step 2/3: Running docker build${NC} ..."
104
+
105
+ if ! command -v docker &>/dev/null; then
106
+ fail "docker command not found"
107
+ hint "Install Docker: https://docs.docker.com/get-docker/"
108
+ stop_at "Step 2"
109
+ fi
110
+
111
+ if [ -f "$REPO_DIR/Dockerfile" ]; then
112
+ DOCKER_CONTEXT="$REPO_DIR"
113
+ elif [ -f "$REPO_DIR/server/Dockerfile" ]; then
114
+ DOCKER_CONTEXT="$REPO_DIR/server"
115
+ else
116
+ fail "No Dockerfile found in repo root or server/ directory"
117
+ stop_at "Step 2"
118
+ fi
119
+
120
+ log " Found Dockerfile in $DOCKER_CONTEXT"
121
+
122
+ BUILD_OK=false
123
+ BUILD_OUTPUT=$(run_with_timeout "$DOCKER_BUILD_TIMEOUT" docker build "$DOCKER_CONTEXT" 2>&1) && BUILD_OK=true
124
+
125
+ if [ "$BUILD_OK" = true ]; then
126
+ pass "Docker build succeeded"
127
+ else
128
+ fail "Docker build failed (timeout=${DOCKER_BUILD_TIMEOUT}s)"
129
+ printf "%s\n" "$BUILD_OUTPUT" | tail -20
130
+ stop_at "Step 2"
131
+ fi
132
+
133
+ log "${BOLD}Step 3/3: Running openenv validate${NC} ..."
134
+
135
+ if ! command -v openenv &>/dev/null; then
136
+ fail "openenv command not found"
137
+ hint "Install it: pip install openenv-core"
138
+ stop_at "Step 3"
139
+ fi
140
+
141
+ VALIDATE_OK=false
142
+ VALIDATE_OUTPUT=$(cd "$REPO_DIR" && openenv validate 2>&1) && VALIDATE_OK=true
143
+
144
+ if [ "$VALIDATE_OK" = true ]; then
145
+ pass "openenv validate passed"
146
+ [ -n "$VALIDATE_OUTPUT" ] && log " $VALIDATE_OUTPUT"
147
+ else
148
+ fail "openenv validate failed"
149
+ printf "%s\n" "$VALIDATE_OUTPUT"
150
+ stop_at "Step 3"
151
+ fi
152
+
153
+ printf "\n"
154
+ printf "${BOLD}========================================${NC}\n"
155
+ printf "${GREEN}${BOLD} All 3/3 checks passed!${NC}\n"
156
+ printf "${GREEN}${BOLD} Your submission is ready to submit.${NC}\n"
157
+ printf "${BOLD}========================================${NC}\n"
158
+ printf "\n"
159
+ exit 0