ASC8384 commited on
Commit
60a7b9d
·
1 Parent(s): 1ee1a5c

playwright

Browse files
Files changed (4) hide show
  1. Dockerfile +65 -0
  2. README.md +9 -4
  3. main.py +0 -1
  4. poster/poster.py +9 -9
Dockerfile ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # 安装系统依赖
4
+ RUN apt-get update && apt-get install -y \
5
+ wget \
6
+ gnupg \
7
+ ca-certificates \
8
+ fonts-liberation \
9
+ libasound2 \
10
+ libatk-bridge2.0-0 \
11
+ libatk1.0-0 \
12
+ libc6 \
13
+ libcairo2 \
14
+ libcups2 \
15
+ libdbus-1-3 \
16
+ libexpat1 \
17
+ libfontconfig1 \
18
+ libgcc1 \
19
+ libgconf-2-4 \
20
+ libgdk-pixbuf2.0-0 \
21
+ libglib2.0-0 \
22
+ libgtk-3-0 \
23
+ libnspr4 \
24
+ libnss3 \
25
+ libpango-1.0-0 \
26
+ libpangocairo-1.0-0 \
27
+ libstdc++6 \
28
+ libx11-6 \
29
+ libx11-xcb1 \
30
+ libxcb1 \
31
+ libxcomposite1 \
32
+ libxcursor1 \
33
+ libxdamage1 \
34
+ libxext6 \
35
+ libxfixes3 \
36
+ libxi6 \
37
+ libxrandr2 \
38
+ libxrender1 \
39
+ libxss1 \
40
+ libxtst6 \
41
+ lsb-release \
42
+ wget \
43
+ xdg-utils \
44
+ && rm -rf /var/lib/apt/lists/*
45
+
46
+ WORKDIR /app
47
+
48
+ # 复制requirements文件
49
+ COPY requirements.txt .
50
+
51
+ # 安装Python依赖
52
+ RUN pip install --no-cache-dir -r requirements.txt
53
+
54
+ # 安装playwright浏览器
55
+ RUN playwright install chromium
56
+ RUN playwright install-deps chromium
57
+
58
+ # 复制应用代码
59
+ COPY . .
60
+
61
+ # 暴露端口
62
+ EXPOSE 7860
63
+
64
+ # 启动应用
65
+ CMD ["python", "app.py"]
README.md CHANGED
@@ -3,9 +3,8 @@ title: P2P Paper-to-Poster Generator
3
  emoji: 🎓
4
  colorFrom: blue
5
  colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.32.1
8
- app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
@@ -19,10 +18,15 @@ license: mit
19
 
20
  ## 🚀 Try it on Hugging Face Spaces
21
 
22
- This application is deployed on Hugging Face Spaces! You can try it directly in your browser without any installation:
23
 
24
  **🎓 [Launch P2P Paper-to-Poster Generator](https://huggingface.co/spaces/ASC8384/P2P)**
25
 
 
 
 
 
 
26
  ### Quick Start on Spaces:
27
  1. Upload your PDF research paper
28
  2. Enter your OpenAI API key and base URL (if using proxy)
@@ -41,6 +45,7 @@ This application is deployed on Hugging Face Spaces! You can try it directly in
41
  - Direct JSON structure display
42
  - Support for multiple AI models
43
  - Flexible API configuration
 
44
 
45
  ## Overview
46
 
 
3
  emoji: 🎓
4
  colorFrom: blue
5
  colorTo: purple
6
+ sdk: docker
7
+ app_port: 7860
 
8
  pinned: false
9
  license: mit
10
  ---
 
18
 
19
  ## 🚀 Try it on Hugging Face Spaces
20
 
21
+ This application is deployed on Hugging Face Spaces using Docker SDK to support advanced dependencies like Playwright! You can try it directly in your browser without any installation:
22
 
23
  **🎓 [Launch P2P Paper-to-Poster Generator](https://huggingface.co/spaces/ASC8384/P2P)**
24
 
25
+ ### Docker Deployment on HF Spaces:
26
+ 1. **SDK**: Uses `docker` instead of `gradio` to support system-level dependencies
27
+ 2. **Playwright Support**: Automatically installs and configures Playwright browsers
28
+ 3. **Pre-built Environment**: No manual setup required for complex dependencies
29
+
30
  ### Quick Start on Spaces:
31
  1. Upload your PDF research paper
32
  2. Enter your OpenAI API key and base URL (if using proxy)
 
45
  - Direct JSON structure display
46
  - Support for multiple AI models
47
  - Flexible API configuration
48
+ - Advanced layout optimization with Playwright
49
 
50
  ## Overview
51
 
main.py CHANGED
@@ -11,7 +11,6 @@ from poster.poster import (
11
  generate_poster_v3,
12
  replace_figures_in_poster,
13
  replace_figures_size_in_poster,
14
- take_screenshot,
15
  )
16
 
17
 
 
11
  generate_poster_v3,
12
  replace_figures_in_poster,
13
  replace_figures_size_in_poster,
 
14
  )
15
 
16
 
poster/poster.py CHANGED
@@ -451,15 +451,15 @@ Now there are {proportion:.0%} blank spaces. Please regenerate the content to cr
451
  ).content
452
 
453
 
454
- def take_screenshot(output: str, html: str):
455
- with sync_playwright() as p:
456
- browser = p.chromium.launch(headless=True)
457
- page = browser.new_page(viewport={"width": 1280, "height": 100})
458
- page.set_content(html)
459
- page.screenshot(
460
- type="png", path=output.replace(".json", ".png"), full_page=True
461
- )
462
- browser.close()
463
 
464
 
465
  def replace_figures_in_svg(svg: str, figures: list[str]) -> str:
 
451
  ).content
452
 
453
 
454
+ # def take_screenshot(output: str, html: str):
455
+ # with sync_playwright() as p:
456
+ # browser = p.chromium.launch(headless=True)
457
+ # page = browser.new_page(viewport={"width": 1280, "height": 100})
458
+ # page.set_content(html)
459
+ # page.screenshot(
460
+ # type="png", path=output.replace(".json", ".png"), full_page=True
461
+ # )
462
+ # browser.close()
463
 
464
 
465
  def replace_figures_in_svg(svg: str, figures: list[str]) -> str: