Skip to content

Commit a815363

Browse files
committed
Clean docker containers
1 parent 7e59558 commit a815363

File tree

6 files changed

+48
-84
lines changed

6 files changed

+48
-84
lines changed

Dockerfile.gradio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ WORKDIR /app
3131

3232
COPY ./src/gradio_app.py ./src/gradio_app.py
3333

34+
ENV PYTHONUNBUFFERED=1
3435
ENV PYTHONPATH "${PYTHONPATH}:/app/src"
3536

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ifeq ($(HAS_GPU), 1)
2424
echo "Warning: Ollama GPU container may not be fully healthy yet, but continuing..."; \
2525
fi
2626
@echo "Starting all services with translation support..."
27-
docker compose -f docker-compose-gpu.yml up --build pdf-document-layout-analysis-gpu-translation pdf-document-layout-analysis-gui-gpu-translation
27+
docker compose -f docker-compose-gpu.yml up --build pdf-document-layout-analysis-gpu pdf-document-layout-analysis-gui-gpu
2828
else
2929
@echo "No NVIDIA GPU detected, starting with translation support (CPU Ollama)"
3030
@echo "Starting Ollama container first..."
@@ -43,7 +43,7 @@ else
4343
echo "Warning: Ollama container may not be fully healthy yet, but continuing..."; \
4444
fi
4545
@echo "Starting all services with translation support..."
46-
docker compose -f docker-compose.yml up --build pdf-document-layout-analysis-translation pdf-document-layout-analysis-gui-translation
46+
docker compose -f docker-compose.yml up --build pdf-document-layout-analysis pdf-document-layout-analysis-gui
4747
endif
4848

4949

@@ -66,7 +66,7 @@ start_no_gpu:
6666
echo "Warning: Ollama container may not be fully healthy yet, but continuing..."; \
6767
fi
6868
@echo "Starting all services with translation support..."
69-
docker compose up --build pdf-document-layout-analysis-translation pdf-document-layout-analysis-gui-translation
69+
docker compose up --build pdf-document-layout-analysis pdf-document-layout-analysis-gui
7070

7171
stop:
7272
docker compose stop

docker-compose-gpu.yml

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,6 @@ services:
1919
entrypoint: [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--chdir", "./src", "app:app", "--bind", "0.0.0.0:5060", "--timeout", "10000"]
2020
init: true
2121
restart: unless-stopped
22-
build:
23-
context: .
24-
dockerfile: Dockerfile
25-
ports:
26-
- "5060:5060"
27-
deploy:
28-
resources:
29-
reservations:
30-
devices:
31-
- driver: nvidia
32-
count: 1
33-
capabilities: [ gpu ]
34-
environment:
35-
- RESTART_IF_NO_GPU=$RESTART_IF_NO_GPU
36-
- OLLAMA_HOST=http://localhost:11434
37-
networks:
38-
- pdf-analysis-network
39-
40-
pdf-document-layout-analysis-gpu-translation:
41-
container_name: pdf-document-layout-analysis-gpu-translation
42-
entrypoint: [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--chdir", "./src", "app:app", "--bind", "0.0.0.0:5060", "--timeout", "10000"]
43-
init: true
44-
restart: unless-stopped
4522
build:
4623
context: .
4724
dockerfile: Dockerfile
@@ -68,23 +45,6 @@ services:
6845
entrypoint: [ "python", "./src/gradio_app.py" ]
6946
init: true
7047
restart: unless-stopped
71-
build:
72-
context: .
73-
dockerfile: Dockerfile.gradio
74-
ports:
75-
- "7860:7860"
76-
depends_on:
77-
- pdf-document-layout-analysis-gpu
78-
environment:
79-
- API_BASE_URL=http://pdf-document-layout-analysis-gpu:5060
80-
networks:
81-
- pdf-analysis-network
82-
83-
pdf-document-layout-analysis-gui-gpu-translation:
84-
container_name: pdf-document-layout-analysis-gui-gpu-translation
85-
entrypoint: [ "python", "./src/gradio_app.py" ]
86-
init: true
87-
restart: unless-stopped
8848
build:
8949
context: .
9050
dockerfile: Dockerfile.gradio
@@ -93,10 +53,10 @@ services:
9353
depends_on:
9454
ollama-gpu:
9555
condition: service_healthy
96-
pdf-document-layout-analysis-gpu-translation:
56+
pdf-document-layout-analysis-gpu:
9757
condition: service_started
9858
environment:
99-
- API_BASE_URL=http://pdf-document-layout-analysis-gpu-translation:5060
59+
- API_BASE_URL=http://pdf-document-layout-analysis-gpu:5060
10060
networks:
10161
- pdf-analysis-network
10262

docker-compose.yml

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@ services:
2121
entrypoint: [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--chdir", "./src", "app:app", "--bind", "0.0.0.0:5060", "--timeout", "10000"]
2222
init: true
2323
restart: unless-stopped
24-
build:
25-
context: .
26-
dockerfile: Dockerfile
27-
ports:
28-
- "5060:5060"
29-
environment:
30-
- OLLAMA_HOST=http://localhost:11434
31-
networks:
32-
- pdf-analysis-network
33-
34-
pdf-document-layout-analysis-translation:
35-
container_name: pdf-document-layout-analysis-translation
36-
entrypoint: [ "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "--chdir", "./src", "app:app", "--bind", "0.0.0.0:5060", "--timeout", "10000"]
37-
init: true
38-
restart: unless-stopped
3924
build:
4025
context: .
4126
dockerfile: Dockerfile
@@ -54,23 +39,6 @@ services:
5439
entrypoint: [ "python", "./src/gradio_app.py" ]
5540
init: true
5641
restart: unless-stopped
57-
build:
58-
context: .
59-
dockerfile: Dockerfile.gradio
60-
ports:
61-
- "7860:7860"
62-
depends_on:
63-
- pdf-document-layout-analysis
64-
environment:
65-
- API_BASE_URL=http://pdf-document-layout-analysis:5060
66-
networks:
67-
- pdf-analysis-network
68-
69-
pdf-document-layout-analysis-gui-translation:
70-
container_name: pdf-document-layout-analysis-gui-translation
71-
entrypoint: [ "python", "./src/gradio_app.py" ]
72-
init: true
73-
restart: unless-stopped
7442
build:
7543
context: .
7644
dockerfile: Dockerfile.gradio
@@ -79,10 +47,10 @@ services:
7947
depends_on:
8048
ollama:
8149
condition: service_healthy
82-
pdf-document-layout-analysis-translation:
50+
pdf-document-layout-analysis:
8351
condition: service_started
8452
environment:
85-
- API_BASE_URL=http://pdf-document-layout-analysis-translation:5060
53+
- API_BASE_URL=http://pdf-document-layout-analysis:5060
8654
networks:
8755
- pdf-analysis-network
8856

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ start:
7575
echo "Warning: Ollama GPU container may not be fully healthy yet, but continuing..."
7676
fi
7777
echo "Starting all services with translation support..."
78-
docker compose -f docker-compose-gpu.yml up --build pdf-document-layout-analysis-gpu-translation pdf-document-layout-analysis-gui-gpu-translation
78+
docker compose -f docker-compose-gpu.yml up --build pdf-document-layout-analysis-gpu pdf-document-layout-analysis-gui-gpu
7979
else
8080
echo "No NVIDIA GPU detected, starting with translation support (CPU Ollama)"
8181
echo "Starting Ollama container first..."
@@ -95,7 +95,7 @@ start:
9595
echo "Warning: Ollama container may not be fully healthy yet, but continuing..."
9696
fi
9797
echo "Starting all services with translation support..."
98-
docker compose -f docker-compose.yml up --build pdf-document-layout-analysis-translation pdf-document-layout-analysis-gui-translation
98+
docker compose -f docker-compose.yml up --build pdf-document-layout-analysis pdf-document-layout-analysis-gui
9999
fi
100100

101101
start_no_gpu:
@@ -119,7 +119,7 @@ start_no_gpu:
119119
echo "Warning: Ollama container may not be fully healthy yet, but continuing..."
120120
fi
121121
echo "Starting all services with translation support..."
122-
docker compose up --build pdf-document-layout-analysis-translation pdf-document-layout-analysis-gui-translation
122+
docker compose up --build pdf-document-layout-analysis pdf-document-layout-analysis-gui
123123

124124
start_no_translation:
125125
mkdir -p ./models

src/gradio_app.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,44 @@
55
import tempfile
66
import base64
77
import zipfile
8+
import time
89

910
API_BASE_URL = os.environ.get("API_BASE_URL", "http://localhost:5060")
1011

1112

13+
def wait_for_backend(max_retries: int = 60, retry_interval: int = 2) -> bool:
14+
print("\n" + "=" * 80, flush=True)
15+
print("⏳ Waiting for PDF Analysis backend service to be ready...".center(80), flush=True)
16+
print("=" * 80 + "\n", flush=True)
17+
18+
for attempt in range(1, max_retries + 1):
19+
try:
20+
response = requests.get(f"{API_BASE_URL}/info", timeout=5)
21+
if response.status_code == 200:
22+
print("=" * 80, flush=True)
23+
print("✅ PDF DOCUMENT LAYOUT ANALYSIS UI IS READY!".center(80), flush=True)
24+
print("=" * 80, flush=True)
25+
print("", flush=True)
26+
print("🌐 Access the UI at:", flush=True)
27+
print(" → http://localhost:7860", flush=True)
28+
print("", flush=True)
29+
print(f"🔗 Backend API: {API_BASE_URL}", flush=True)
30+
print("", flush=True)
31+
print("=" * 80, flush=True)
32+
print("=" * 80 + "\n", flush=True)
33+
return True
34+
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
35+
time.sleep(retry_interval)
36+
except Exception as e:
37+
print(f" Unexpected error while checking backend: {str(e)}", flush=True)
38+
time.sleep(retry_interval)
39+
40+
print("\n" + "=" * 80, flush=True)
41+
print("❌ Backend service did not become ready in time!".center(80), flush=True)
42+
print("=" * 80 + "\n", flush=True)
43+
return False
44+
45+
1246
def validate_pdf_file(pdf_file):
1347
"""Validate that the uploaded file is a valid PDF"""
1448
if pdf_file is None:
@@ -901,7 +935,8 @@ def convert_to_html(
901935

902936

903937
if __name__ == "__main__":
904-
print("Starting Gradio interface...")
905-
print(f"API Base URL: {API_BASE_URL}")
938+
if not wait_for_backend():
939+
print("⚠️ Starting UI anyway, but backend may not be available.", flush=True)
940+
print(" Please check that the API service is running.\n", flush=True)
906941

907942
app.launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True, max_file_size="100mb")

0 commit comments

Comments
 (0)