Skip to content

Commit 7a4ca38

Browse files
committed
Feat: Dockerized the solution
1 parent b4b24d7 commit 7a4ca38

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Stage 1: Build
2+
FROM --platform=linux/amd64 python:3.11.8-slim as build
3+
WORKDIR /app
4+
5+
# Install build dependencies
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Install build dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
build-essential \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
16+
COPY . .
17+
18+
RUN chmod u+x setup.sh
19+
CMD ["./setup.sh"]
20+
21+
# Install CPU-optimized PyTorch
22+
RUN pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
23+
24+
# Install other requirements
25+
RUN pip install --no-cache-dir -r requirements.txt
26+
27+
28+
# Stage 2: Runtime
29+
FROM --platform=linux/amd64 python:3.11.8-slim
30+
WORKDIR /app
31+
32+
# Copy only the necessary files from the build stage
33+
COPY --from=build /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
34+
COPY --from=build /app /app
35+
36+
37+
# Set entrypoint
38+
ENTRYPOINT ["uvicorn", "main:app", "--reload"]

main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,6 @@ async def get_powerbackup_quotation() -> Dict[str, Any]:
199199
return quotation
200200
except Exception as e:
201201
raise HTTPException(status_code=500, detail=f"Failed to load quotation: {e}")
202+
203+
if __name__ == "__main__":
204+
uvicorn.run(app, host="0.0.0.0", port=8080)

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ tenacity==8.5.0
111111
tiktoken==0.7.0
112112
timm==1.0.8
113113
tokenizers==0.19.1
114-
torch==2.4.0
115-
torchvision==0.19.0
116114
tqdm==4.66.5
117115
transformers==4.44.1
118116
typing-inspect==0.9.0

setup.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# Install libgl1
3+
sudo apt-get update && sudo apt-get install libgl1
4+
5+
# Install tesseract-ocr
6+
sudo apt install tesseract-ocr -y
7+
8+
# Install libtesseract-dev
9+
sudo apt install libtesseract-dev -y
10+
11+
# Install poppler-utils
12+
sudo apt-get install poppler-utils -y

0 commit comments

Comments
 (0)