Rivalcoder commited on
Commit
078cae9
·
1 Parent(s): 724731a

Use of Playright

Browse files
Files changed (2) hide show
  1. Dockerfile +31 -4
  2. kanon_api.py +4 -0
Dockerfile CHANGED
@@ -1,19 +1,46 @@
 
1
  FROM python:3.11-slim
2
 
 
3
  WORKDIR /app
4
 
5
  # Install system dependencies required by Playwright
6
  RUN apt-get update && apt-get install -y \
7
- libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 \
8
- libx11-xcb1 libxcomposite1 libxdamage1 libxrandr2 libgbm1 \
9
- libpango-1.0-0 libpangocairo-1.0-0 libasound2 fonts-liberation \
10
- libglib2.0-0 libdrm2 \
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  && rm -rf /var/lib/apt/lists/*
12
 
 
13
  COPY requirements.txt .
14
  RUN pip install --no-cache-dir -r requirements.txt
15
 
 
 
 
 
 
 
 
16
  COPY . .
17
 
 
18
  EXPOSE 7860
 
 
19
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use official Python slim image
2
  FROM python:3.11-slim
3
 
4
+ # Set working directory
5
  WORKDIR /app
6
 
7
  # Install system dependencies required by Playwright
8
  RUN apt-get update && apt-get install -y \
9
+ curl \
10
+ gnupg \
11
+ ca-certificates \
12
+ libnss3 \
13
+ libatk1.0-0 \
14
+ libatk-bridge2.0-0 \
15
+ libcups2 \
16
+ libx11-xcb1 \
17
+ libxcomposite1 \
18
+ libxdamage1 \
19
+ libxrandr2 \
20
+ libgbm1 \
21
+ libpango-1.0-0 \
22
+ libpangocairo-1.0-0 \
23
+ libasound2 \
24
+ fonts-liberation \
25
+ libglib2.0-0 \
26
+ libdrm2 \
27
  && rm -rf /var/lib/apt/lists/*
28
 
29
+ # Copy requirements and install
30
  COPY requirements.txt .
31
  RUN pip install --no-cache-dir -r requirements.txt
32
 
33
+ # Set Playwright browsers to a writable path
34
+ ENV PLAYWRIGHT_BROWSERS_PATH=/tmp/playwright-browsers
35
+
36
+ # Install Playwright browsers
37
+ RUN playwright install chromium
38
+
39
+ # Copy app files
40
  COPY . .
41
 
42
+ # Expose port
43
  EXPOSE 7860
44
+
45
+ # Run FastAPI
46
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
kanon_api.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  from playwright.async_api import async_playwright
2
  from bs4 import BeautifulSoup
3
  import asyncio
 
1
+ import os
2
+ os.environ["PLAYWRIGHT_BROWSERS_PATH"] = "/tmp/playwright-browsers"
3
+
4
+
5
  from playwright.async_api import async_playwright
6
  from bs4 import BeautifulSoup
7
  import asyncio