Skip to content

Commit 214835b

Browse files
Merge branch 'web-gui' into dev
2 parents 0abd268 + 6a4715b commit 214835b

12 files changed

Lines changed: 1283 additions & 13 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ scripts/notfinished_*
2323
scripts/**/*perso*
2424
latest_release_notes_*.md
2525
wdoc_user_cache_dir/
26+
27+
docker/custom_env
28+
docker/vectorstore
29+
docker/wdoc_cache

README.md

Lines changed: 162 additions & 1 deletion
Large diffs are not rendered by default.

docker/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM python:3.13-slim
2+
3+
# Set working directory to allow the gui.py to be in the same directory as where we run
4+
WORKDIR /app
5+
6+
# Install system dependencies required by wdoc
7+
RUN apt-get update && apt-get install -y \
8+
git \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Create a non-root user with UID:GID 1000:1000
12+
# This matches most default user IDs on Linux systems, allowing proper file permissions for volumes
13+
RUN groupadd -g 1000 wdoc && \
14+
useradd -u 1000 -g 1000 -m -s /bin/bash wdoc
15+
16+
# Install Python packages
17+
# Using uv for faster installation, but pip is fine too
18+
RUN pip install --no-cache-dir uv && \
19+
uv pip install --system wdoc gradio && \
20+
rm -rf /root/.cache
21+
22+
# Copy the GUI script
23+
COPY gui.py /app/gui.py
24+
25+
# Expose Gradio's default port
26+
EXPOSE 7860
27+
28+
# Switch to non-root user for running the application
29+
USER wdoc
30+
31+
# Create .local directory structure for the wdoc user and set permissions
32+
RUN mkdir -p /home/wdoc/.local && \
33+
mkdir -p /home/wdoc/.cache/wdoc
34+
USER root
35+
RUN chown -R wdoc:wdoc /home/wdoc/.local && \
36+
chown -R wdoc:wdoc /home/wdoc/.cache/wdoc && \
37+
chown -R wdoc:wdoc /app
38+
USER wdoc
39+
40+
# Set environment variables
41+
ENV GRADIO_SERVER_NAME="0.0.0.0"
42+
ENV HOME="/home/wdoc"
43+
44+
# Run the Gradio app
45+
CMD ["python", "gui.py"]

docker/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# wdoc Docker Setup
2+
3+
This directory contains a dockerized Gradio web interface for wdoc, designed for easy deployment and use.
4+
5+
## Quick Start
6+
7+
1. **Configure environment variables**: Copy and edit the environment file:
8+
```bash
9+
cp custom_env.example custom_env
10+
# Edit custom_env to add your API keys (OPENAI_API_KEY, etc.)
11+
```
12+
13+
2. **Start the service**:
14+
```bash
15+
docker-compose up -d
16+
```
17+
18+
3. **Access the web interface**: Open your browser to `http://localhost:7618`
19+
20+
## Architecture
21+
22+
- **Container user**: Runs as non-root user `wdoc` (UID:GID 1000:1000) for security
23+
- **Port**: Exposes Gradio on port 7618 (mapped from internal port 7860)
24+
- **Volumes**:
25+
- `./vectorstore`: Persistent storage for document embeddings
26+
- `./wdoc_cache`: LLM cache to reduce API costs and improve performance
27+
28+
## Troubleshooting
29+
30+
### Permission Errors
31+
32+
If you encounter permission errors on first startup, particularly related to the cache directory, this is typically because Docker created the volume directories with root ownership.
33+
34+
**Solution**: Change ownership of the docker directory to match the container's user (UID:GID 1000:1000):
35+
36+
```bash
37+
# From the docker directory
38+
sudo chown -R 1000:1000 ./vectorstore ./wdoc_cache
39+
40+
# Or if the directories don't exist yet:
41+
mkdir -p ./vectorstore ./wdoc_cache
42+
sudo chown -R 1000:1000 ./vectorstore ./wdoc_cache
43+
```
44+
45+
**Alternative**: If you're running with a different user ID, you can modify the `docker-compose.yml` to use your current user:
46+
47+
```yaml
48+
user: "${UID}:${GID}"
49+
```
50+
51+
Then run with:
52+
```bash
53+
UID=$(id -u) GID=$(id -g) docker-compose up -d
54+
```
55+
56+
### Checking Logs
57+
58+
To view the application logs:
59+
```bash
60+
docker-compose logs -f wdoc-gui
61+
```
62+
63+
### Rebuilding After Changes
64+
65+
If you've modified `gui.py` or `Dockerfile`:
66+
```bash
67+
docker-compose down
68+
docker-compose build --no-cache
69+
docker-compose up -d
70+
```
71+
72+
## Configuration
73+
74+
### Environment Variables
75+
76+
Create a `custom_env` file with your configuration:
77+
78+
```bash
79+
# Required: API keys for your LLM provider
80+
OPENAI_API_KEY=sk-...
81+
# Or for other providers:
82+
# ANTHROPIC_API_KEY=...
83+
# GEMINI_API_KEY=...
84+
85+
# Optional: Default models
86+
WDOC_DEFAULT_MODEL=openai/gpt-4o-mini
87+
WDOC_DEFAULT_EMBED_MODEL=openai/text-embedding-3-small
88+
89+
# Optional: Langfuse integration (if using)
90+
LANGFUSE_PUBLIC_KEY=pk-...
91+
LANGFUSE_SECRET_KEY=sk-...
92+
LANGFUSE_HOST=https://cloud.langfuse.com
93+
```
94+
95+
### Volume Paths
96+
97+
You can customize volume paths using environment variables in `docker-compose.yml`:
98+
99+
```bash
100+
VECTORSTORE_PATH=/your/custom/path/vectorstore docker-compose up -d
101+
CACHE_PATH=/your/custom/path/cache docker-compose up -d
102+
```
103+
104+
## Security Notes
105+
106+
- The container runs as a non-root user for improved security
107+
- Security option `no-new-privileges` prevents privilege escalation
108+
- No unnecessary capabilities are granted
109+
- Network access is controlled (uses `host.docker.internal` for local services like Langfuse)
110+
111+
## For Developers
112+
113+
### Building Locally
114+
115+
```bash
116+
docker build -t wdoc-gui .
117+
docker run -p 7618:7860 \
118+
-v $(pwd)/vectorstore:/app/vectorstore \
119+
-v $(pwd)/wdoc_cache:/home/wdoc/.cache/wdoc \
120+
--env-file custom_env \
121+
wdoc-gui
122+
```
123+
124+
### Modifying the GUI
125+
126+
The Gradio interface is defined in `gui.py`. After making changes, rebuild the container to see them take effect.
127+
128+
## Additional Resources
129+
130+
- [wdoc GitHub Repository](https://github.com/thiswillbeyourgithub/wdoc)
131+
- [wdoc Documentation](https://wdoc.readthedocs.io/)
132+
- [Gradio Documentation](https://gradio.app)
133+
134+
---
135+
136+
*This Docker setup was created with assistance from [aider.chat](https://github.com/Aider-AI/aider/)*

docker/docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
services:
2+
wdoc-gui:
3+
container_name: wdoc-gui
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
ports:
8+
- "7618:7860"
9+
volumes:
10+
# Mount vectorstore directory to persist and share vectorstore data
11+
- ${VECTORSTORE_PATH:-./vectorstore}:/app/vectorstore
12+
# Optionally mount cache directory to persist LLM caches
13+
- ${CACHE_PATH:-./wdoc_cache}:/home/wdoc/.cache/wdoc
14+
# Load environment variables from the env file
15+
env_file:
16+
- custom_env
17+
restart: unless-stopped
18+
user: 1000:1000
19+
security_opt:
20+
- no-new-privileges:true
21+
# if using langfuse for example
22+
extra_hosts:
23+
- "host.docker.internal:host-gateway"

docker/env.example

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# wdoc Docker Environment Configuration
2+
# Copy this file to 'env' and customize the values for your setup
3+
4+
# Path to vectorstore inside container (usually no need to change)
5+
VECTORSTORE_PATH=/app/vectorstore
6+
7+
# Default models for wdoc
8+
WDOC_DEFAULT_MODEL=openrouter/google/gemini-2.5-pro
9+
WDOC_DEFAULT_QUERY_EVAL_MODEL=openrouter/google/gemini-2.5-flash
10+
WDOC_DEFAULT_EMBED_MODEL=openai/text-embedding-3-small
11+
12+
# API Keys - REQUIRED: Add your API keys here
13+
# At minimum, you need an OpenRouter API key for most models
14+
OPENROUTER_API_KEY=your_api_key_here
15+
16+
# Optional: Other API keys if using different providers directly
17+
# OPENAI_API_KEY=
18+
# ANTHROPIC_API_KEY=
19+
# MISTRAL_API_KEY=
20+
21+
# Optional: Langfuse configuration for observability
22+
# WDOC_LANGFUSE_PUBLIC_KEY=
23+
# WDOC_LANGFUSE_SECRET_KEY=
24+
# WDOC_LANGFUSE_HOST=
25+
26+
# Optional: Gradio server configuration
27+
GRADIO_SERVER_NAME=0.0.0.0
28+
GRADIO_SERVER_PORT=7860
29+
30+
# Optional: wdoc behavior settings
31+
# WDOC_VERBOSE=false
32+
# WDOC_DEBUG=false
33+
# WDOC_EXPIRE_CACHE_DAYS=0

0 commit comments

Comments
 (0)