Skip to content

Commit 5397468

Browse files
committed
WIP
1 parent ccb2f29 commit 5397468

9 files changed

Lines changed: 2156 additions & 23 deletions

File tree

src/overcooked_demo/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ A web application where humans can play Overcooked with trained AI agents.
77

88
* [Installation](#installation)
99
* [Usage](#usage)
10+
* [Docker Deployment](#docker-deployment)
11+
* [Local Run with uv](#local-run-with-uv)
12+
* [Command Line](#command-line)
1013
* [Dependencies](#dependencies)
1114
* [Using Pre-trained Agents](#using-pre-trained-agents)
1215
* [Updating](#updating)
@@ -17,8 +20,14 @@ A web application where humans can play Overcooked with trained AI agents.
1720

1821
Building the server image requires [Docker](https://docs.docker.com/get-docker/)
1922

23+
For local development with uv, you'll need:
24+
- Python 3.7 or later
25+
- [uv](https://github.com/astral-sh/uv) - Install with `pip install uv`
26+
2027
## Usage
2128

29+
### Docker Deployment
30+
2231
The server can be deployed locally using the driver script included in the repo. To run the production server, use the command
2332
```bash
2433
./up.sh production
@@ -36,6 +45,23 @@ In order to kill the production server, run
3645
./down.sh
3746
```
3847

48+
### Local Run with uv
49+
50+
To run the server locally using uv without Docker, use:
51+
52+
```bash
53+
./up.sh local
54+
```
55+
56+
This will:
57+
1. Create a virtual environment in the server directory if it doesn't exist
58+
2. Install all dependencies using uv
59+
3. Start the server on port 5000
60+
61+
After running this command, navigate to http://localhost:5000
62+
63+
### Command Line
64+
3965
You can also start the server via the command line. After installing the `overcooked_ai` via pip, you can start the server by typing
4066

4167
```

src/overcooked_demo/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version : '3.7'
2-
31
services:
42
app:
53
build:
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
1-
FROM python:3.7-buster
1+
FROM python:3.9-slim
22

33
ARG BUILD_ENV
44
ARG OVERCOOKED_BRANCH
55
ARG GRAPHICS
66

77
WORKDIR /app
88

9-
# Install non-chai dependencies
10-
COPY ./requirements.txt ./requirements.txt
11-
RUN pip install -r requirements.txt
9+
# Install uv
10+
RUN pip install uv
1211

13-
# Install eventlet production server if production build
14-
RUN if [ "$BUILD_ENV" = "production" ] ; then pip install eventlet ; fi
12+
# Create a virtual environment for uv
13+
RUN uv venv
14+
15+
# Copy the pyproject.toml for installation
16+
COPY ./pyproject.toml ./pyproject.toml
17+
COPY ./dev_helper.py ./dev_helper.py
1518

16-
# Clone chai code
19+
# Clone chai code for the human_aware_rl module
20+
RUN apt-get update && apt-get install -y git
1721
RUN git clone --recursive https://github.com/HumanCompatibleAI/overcooked_ai.git --branch $OVERCOOKED_BRANCH --single-branch /overcooked_ai
1822

1923
# Dummy data_dir so things don't break
2024
RUN echo "import os; DATA_DIR=os.path.abspath('.')" >> /overcooked_ai/src/human_aware_rl/data_dir.py
2125

22-
# Install chai dependencies
23-
RUN pip install -e '/overcooked_ai[harl]'
26+
# Install server dependencies
27+
RUN . .venv/bin/activate && uv pip install -e .
2428

25-
RUN apt-get -y update
26-
RUN apt-get install -y libgl1-mesa-dev
29+
# Install the cloned overcooked_ai in development mode
30+
RUN . .venv/bin/activate && uv pip install -e /overcooked_ai
31+
32+
# Install eventlet production server if production build
33+
RUN if [ "$BUILD_ENV" = "production" ] ; then . .venv/bin/activate && uv pip install "eventlet>=0.39.0" ; fi
34+
35+
# Install needed packages
36+
RUN apt-get update && apt-get install -y \
37+
libgl1-mesa-dev \
38+
&& rm -rf /var/lib/apt/lists/*
2739

2840
# Copy over remaining files
2941
COPY ./static ./static
3042
COPY ./*.py ./
3143
COPY ./graphics/$GRAPHICS ./static/js/graphics.js
3244
COPY ./config.json ./config.json
3345

34-
35-
3646
# Set environment variables that will be used by app.py
3747
ENV HOST 0.0.0.0
3848
ENV PORT 5000
3949
ENV CONF_PATH config.json
4050

41-
# Do the thing
51+
# Expose port and run the app, using dev_helper to ensure proper Python path
4252
EXPOSE 5000
43-
CMD ["python", "-u", "app.py"]
53+
CMD [".venv/bin/python", "-m", "dev_helper", "app.py"]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Overcooked Demo Server
2+
3+
This directory contains the server code for the Overcooked AI demo.
4+
5+
## Running with uv
6+
7+
The server now uses [uv](https://github.com/astral-sh/uv) for dependency management and running Python code.
8+
9+
### Prerequisites
10+
11+
Install uv:
12+
13+
```bash
14+
pip install uv
15+
```
16+
17+
### Running the Server
18+
19+
You can run the server directly using:
20+
21+
```bash
22+
uv run app.py
23+
```
24+
25+
Alternatively, use the provided shell script:
26+
27+
```bash
28+
./run_server.sh
29+
```
30+
31+
## Docker
32+
33+
The Dockerfile has been updated to use uv as well. Build and run the Docker container with:
34+
35+
```bash
36+
# Build the container
37+
docker build -t overcooked-server \
38+
--build-arg BUILD_ENV=development \
39+
--build-arg OVERCOOKED_BRANCH=master \
40+
--build-arg GRAPHICS=js .
41+
42+
# Run the container
43+
docker run -p 5000:5000 overcooked-server
44+
```
45+
46+
## Dependencies
47+
48+
Dependencies are now managed through the `pyproject.toml` file. If you need to add or modify dependencies, update this file instead of the legacy `requirements.txt`.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Helper module to add the parent src directory to the Python path.
3+
This allows importing human_aware_rl and other modules from the main project.
4+
5+
Usage:
6+
# At the top of your script (e.g., app.py)
7+
import os
8+
import sys
9+
10+
# Add parent directory to path
11+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
12+
13+
# Now you can import from human_aware_rl
14+
from human_aware_rl.rllib.rllib import load_agent
15+
"""
16+
17+
import os
18+
import sys
19+
import pathlib
20+
21+
def add_src_to_path():
22+
"""Add the parent src directory to the Python path."""
23+
current_dir = pathlib.Path(__file__).parent.absolute()
24+
src_dir = current_dir.parent.parent # ../.. relative to this file
25+
sys.path.insert(0, str(src_dir))
26+
print(f"Added {src_dir} to Python path")
27+
28+
# Automatically add to path when imported
29+
add_src_to_path()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "overcooked_server"
7+
version = "1.0.0"
8+
description = "Server for Overcooked AI demo"
9+
requires-python = ">=3.9"
10+
dependencies = [
11+
"dill",
12+
"numpy<2.0.0",
13+
"certifi>=2020.6.20",
14+
"click>=8.0",
15+
"dnspython>=1.16.0",
16+
"Flask>=2.1.0",
17+
"Flask-SocketIO>=4.3.0",
18+
"greenlet>=0.4.16",
19+
"itsdangerous>=2.0",
20+
"Jinja2>=3.1.0",
21+
"MarkupSafe>=2.0",
22+
"monotonic>=1.5",
23+
"python-engineio>=3.13.0",
24+
"python-socketio>=4.6.0",
25+
"six>=1.15.0",
26+
"Werkzeug>=2.0.3",
27+
"requests>=2.23.0",
28+
"protobuf>=3.19",
29+
"eventlet>=0.39.0",
30+
"ray[rllib]>=2.5.0",
31+
]
32+
33+
[project.optional-dependencies]
34+
tensorflow = [
35+
"tensorflow>=2.14.0",
36+
]
37+
38+
[tool.setuptools]
39+
py-modules = []
40+
41+
[tool.setuptools.package-dir]
42+
"" = "../.."
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# This script runs the Overcooked server using uv
4+
5+
# Check if uv is installed
6+
if ! command -v uv &> /dev/null
7+
then
8+
echo "uv could not be found. Please install it first using 'pip install uv'"
9+
exit 1
10+
fi
11+
12+
# Create a venv if it doesn't exist
13+
if [ ! -d ".venv" ]; then
14+
echo "Creating virtual environment..."
15+
uv venv
16+
fi
17+
18+
# Activate the virtual environment
19+
source .venv/bin/activate
20+
21+
# Install dependencies if needed
22+
if [ ! -f ".venv/.initialized" ]; then
23+
# Install dependencies from pyproject.toml
24+
echo "Installing dependencies from pyproject.toml..."
25+
uv pip install -e .
26+
27+
# Also install root package
28+
echo "Ensuring overcooked_ai is installed..."
29+
ROOT_DIR="$(realpath "$(dirname "$0")/../..")"
30+
uv pip install -e "$ROOT_DIR"
31+
32+
# Try to install tensorflow with a fallback
33+
echo "Attempting to install tensorflow..."
34+
if ! uv pip install -e ".[tensorflow]" 2>/dev/null; then
35+
echo "Could not install latest tensorflow. Trying compatible version..."
36+
# Try a version known to work on many platforms
37+
if ! uv pip install "tensorflow>=2.8.0" 2>/dev/null; then
38+
echo "Warning: Could not install tensorflow. The server will run with limited functionality."
39+
fi
40+
fi
41+
42+
# Mark as initialized
43+
touch .venv/.initialized
44+
fi
45+
46+
# Run the server using the Python interpreter from the venv
47+
echo "Starting server..."
48+
.venv/bin/python -m dev_helper app.py "$@"

0 commit comments

Comments
 (0)