Upload folder using huggingface_hub
Browse files- .gitattributes +6 -0
- .gitignore +175 -0
- .gradio/certificate.pem +31 -0
- README.md +63 -7
- __init__.py +3 -0
- cli.py +17 -0
- convert.py +420 -0
- poetry.lock +0 -0
- pyproject.toml +22 -0
- requirements.txt +5 -0
- static/page11_img1.png +3 -0
- static/page16_img1.png +3 -0
- static/page2_img1.png +3 -0
- static/page3_img1.png +3 -0
- static/page4_img1.png +3 -0
- static/page7_img1.png +3 -0
- test.ipynb +136 -0
- web_interface.py +424 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
static/page11_img1.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
static/page16_img1.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
static/page2_img1.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
static/page3_img1.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
static/page4_img1.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
static/page7_img1.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
|
| 110 |
+
# pdm
|
| 111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 112 |
+
#pdm.lock
|
| 113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 114 |
+
# in version control.
|
| 115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 116 |
+
.pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 121 |
+
__pypackages__/
|
| 122 |
+
|
| 123 |
+
# Celery stuff
|
| 124 |
+
celerybeat-schedule
|
| 125 |
+
celerybeat.pid
|
| 126 |
+
|
| 127 |
+
# SageMath parsed files
|
| 128 |
+
*.sage.py
|
| 129 |
+
|
| 130 |
+
# Environments
|
| 131 |
+
.env
|
| 132 |
+
.venv
|
| 133 |
+
env/
|
| 134 |
+
venv/
|
| 135 |
+
ENV/
|
| 136 |
+
env.bak/
|
| 137 |
+
venv.bak/
|
| 138 |
+
|
| 139 |
+
# Spyder project settings
|
| 140 |
+
.spyderproject
|
| 141 |
+
.spyproject
|
| 142 |
+
|
| 143 |
+
# Rope project settings
|
| 144 |
+
.ropeproject
|
| 145 |
+
|
| 146 |
+
# mkdocs documentation
|
| 147 |
+
/site
|
| 148 |
+
|
| 149 |
+
# mypy
|
| 150 |
+
.mypy_cache/
|
| 151 |
+
.dmypy.json
|
| 152 |
+
dmypy.json
|
| 153 |
+
|
| 154 |
+
# Pyre type checker
|
| 155 |
+
.pyre/
|
| 156 |
+
|
| 157 |
+
# pytype static type analyzer
|
| 158 |
+
.pytype/
|
| 159 |
+
|
| 160 |
+
# Cython debug symbols
|
| 161 |
+
cython_debug/
|
| 162 |
+
|
| 163 |
+
# PyCharm
|
| 164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 168 |
+
#.idea/
|
| 169 |
+
|
| 170 |
+
# PyPI configuration file
|
| 171 |
+
.pypirc
|
| 172 |
+
|
| 173 |
+
data/
|
| 174 |
+
.DS_Store
|
| 175 |
+
.temp
|
.gradio/certificate.pem
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ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
|
@@ -1,12 +1,68 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.20.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: pdf2html
|
| 3 |
+
app_file: web_interface.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 5.20.1
|
|
|
|
|
|
|
| 6 |
---
|
| 7 |
+
# pdf2html
|
| 8 |
|
| 9 |
+
PDF ํ์ผ์ ๋จ์ผ ์ปฌ๋ผ HTML๋ก ๋ณํํ๋ Python ํจํค์ง์
๋๋ค.
|
| 10 |
+
|
| 11 |
+
## ์ค์น
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
# Poetry๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ
|
| 15 |
+
poetry install
|
| 16 |
+
|
| 17 |
+
# ๋๋ pip ์ฌ์ฉ
|
| 18 |
+
pip install pdf2html
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
pip install PyMuPDF beautifulsoup4 langchain gradio gradio-pdf
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
## ์ฌ์ฉ๋ฒ
|
| 28 |
+
|
| 29 |
+
### ๋ช
๋ น์ค ์ธํฐํ์ด์ค
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
# ์ง์ ์คํ
|
| 33 |
+
poerty run python -m pdf2html ๊ฒฝ๋ก/ํ์ผ๋ช
.pdf
|
| 34 |
+
poerty run python -m pdf2html ๊ฒฝ๋ก/ํ์ผ๋ช
.pdf --output ์ถ๋ ฅ๋๋ ํ ๋ฆฌ
|
| 35 |
+
|
| 36 |
+
# ์ค์น ํ ์คํ
|
| 37 |
+
pdf2html ๊ฒฝ๋ก/ํ์ผ๋ช
.pdf
|
| 38 |
+
pdf2html ๊ฒฝ๋ก/ํ์ผ๋ช
.pdf --output ์ถ๋ ฅ๋๋ ํ ๋ฆฌ
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### ์น ์ธํฐํ์ด์ค
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
# ์ง์ ์คํ
|
| 45 |
+
poetry run python -m web_interface
|
| 46 |
+
|
| 47 |
+
# ์ค์น ํ ์คํ
|
| 48 |
+
pdf2html-web
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Python ์ฝ๋์์ ์ฌ์ฉ
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
from pdf2html import PDFToHTMLConverter
|
| 55 |
+
|
| 56 |
+
converter = PDFToHTMLConverter("๊ฒฝ๋ก/ํ์ผ๋ช
.pdf")
|
| 57 |
+
output_path = converter.convert()
|
| 58 |
+
print(f"๋ณํ ์๋ฃ: {output_path}")
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## ์ฃผ์ ๊ธฐ๋ฅ
|
| 62 |
+
|
| 63 |
+
- PDF ๋ฌธ์์ ํ
์คํธ, ์ด๋ฏธ์ง, ํ ์ถ์ถ
|
| 64 |
+
- 1๋จ ์ธ๋ก ๋ ์ด์์์ผ๋ก ์ฌ๊ตฌ์ฑ
|
| 65 |
+
- ๋ฌธ๋จ ๊ตฌ์กฐ ๋ฐ ์์ ์ ์ง
|
| 66 |
+
- ์ด๋ฏธ์ง ์๋ ์ถ์ถ ๋ฐ ํฌํจ
|
| 67 |
+
- ํ ๊ตฌ์กฐ ๊ฐ์ง ๋ฐ HTML ํ
์ด๋ธ๋ก ๋ณํ
|
| 68 |
+
- Gradio ๊ธฐ๋ฐ ์น ์ธํฐํ์ด์ค ์ ๊ณต
|
__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from convert import PDFToHTMLConverter
|
| 2 |
+
|
| 3 |
+
__version__ = "0.1.0"
|
cli.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from convert import PDFToHTMLConverter
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
parser = argparse.ArgumentParser(description="PDF๋ฅผ HTML๋ก ๋ณํ")
|
| 6 |
+
parser.add_argument("pdf_path", help="๋ณํํ PDF ํ์ผ ๊ฒฝ๋ก")
|
| 7 |
+
parser.add_argument("--output", "-o", help="์ถ๋ ฅ ๋๋ ํ ๋ฆฌ (๊ธฐ๋ณธ๊ฐ: PDF์ ๊ฐ์ ๋๋ ํ ๋ฆฌ)")
|
| 8 |
+
|
| 9 |
+
args = parser.parse_args()
|
| 10 |
+
|
| 11 |
+
converter = PDFToHTMLConverter(args.pdf_path, args.output)
|
| 12 |
+
output_path = converter.convert()
|
| 13 |
+
|
| 14 |
+
print(f"๋ณํ ์๋ฃ: {output_path}")
|
| 15 |
+
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
main()
|
convert.py
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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, pdf_path, output_dir=None):
|
| 10 |
+
"""
|
| 11 |
+
PDF๋ฅผ HTML๋ก ๋ณํํ๋ ํด๋์ค ์ด๊ธฐํ
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
pdf_path (str): PDF ํ์ผ ๊ฒฝ๋ก
|
| 15 |
+
output_dir (str, optional): ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ. ๊ธฐ๋ณธ๊ฐ์ PDF์ ๊ฐ์ ๋๋ ํ ๋ฆฌ.
|
| 16 |
+
"""
|
| 17 |
+
self.pdf_path = pdf_path
|
| 18 |
+
self.pdf_name = Path(pdf_path).stem
|
| 19 |
+
|
| 20 |
+
# ํ๋ก์ ํธ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์ .temp ํด๋ ์์ฑ
|
| 21 |
+
current_dir = Path.cwd()
|
| 22 |
+
self.temp_dir = current_dir / ".temp"
|
| 23 |
+
|
| 24 |
+
# ์
๋ ฅ PDF ์ ์ฅ ๋๋ ํ ๋ฆฌ
|
| 25 |
+
self.pdf_dir = self.temp_dir / "temp_input_pdf"
|
| 26 |
+
|
| 27 |
+
# ์ถ๋ ฅ HTML ์ ์ฅ ๋๋ ํ ๋ฆฌ
|
| 28 |
+
self.output_dir = self.temp_dir / "temp_output_html"
|
| 29 |
+
|
| 30 |
+
# ์ด๋ฏธ์ง ์ ์ฅ ๋๋ ํ ๋ฆฌ
|
| 31 |
+
self.img_dir = self.output_dir / "images"
|
| 32 |
+
|
| 33 |
+
# ํ์ํ ๋๋ ํ ๋ฆฌ ์์ฑ
|
| 34 |
+
self.temp_dir.mkdir(exist_ok=True)
|
| 35 |
+
self.pdf_dir.mkdir(exist_ok=True)
|
| 36 |
+
self.output_dir.mkdir(exist_ok=True)
|
| 37 |
+
self.img_dir.mkdir(exist_ok=True)
|
| 38 |
+
|
| 39 |
+
# ๊ณ ์ ๋ ํ์ผ ์ด๋ฆ ์ค์
|
| 40 |
+
self.fixed_pdf_path = self.pdf_dir / "current.pdf"
|
| 41 |
+
|
| 42 |
+
# ํ์ผ ๊ฒฝ๋ก๊ฐ ๋ฌธ์์ด์ธ ๊ฒฝ์ฐ Path ๊ฐ์ฒด๋ก ๋ณํ
|
| 43 |
+
if isinstance(pdf_path, str):
|
| 44 |
+
pdf_path = Path(pdf_path)
|
| 45 |
+
|
| 46 |
+
# ์๋ณธ PDF ํ์ผ์ด ๊ณ ์ ๊ฒฝ๋ก์ ๋ค๋ฅธ ๊ฒฝ์ฐ์๋ง ๋ณต์ฌ
|
| 47 |
+
if pdf_path != self.fixed_pdf_path:
|
| 48 |
+
shutil.copy2(str(pdf_path), str(self.fixed_pdf_path))
|
| 49 |
+
print(f"PDF ํ์ผ ๋ณต์ฌ๋จ: {pdf_path} -> {self.fixed_pdf_path}")
|
| 50 |
+
else:
|
| 51 |
+
print(f"PDF ํ์ผ์ด ์ด๋ฏธ ์ฌ๋ฐ๋ฅธ ์์น์ ์์ต๋๋ค: {self.fixed_pdf_path}")
|
| 52 |
+
|
| 53 |
+
# PyMuPDF ๋ฌธ์ ๊ฐ์ฒด ์ด๊ธฐ
|
| 54 |
+
self.doc = fitz.open(self.fixed_pdf_path)
|
| 55 |
+
|
| 56 |
+
# ๊ฒฐ๊ณผ HTML
|
| 57 |
+
self.html_content = ""
|
| 58 |
+
self.text_html_content = ""
|
| 59 |
+
self.media_html_content = ""
|
| 60 |
+
|
| 61 |
+
def _extract_text_with_structure(self, page):
|
| 62 |
+
"""
|
| 63 |
+
ํ์ด์ง์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๊ณ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์ ์ง
|
| 64 |
+
|
| 65 |
+
Args:
|
| 66 |
+
page (fitz.Page): PDF ํ์ด์ง ๊ฐ์ฒด
|
| 67 |
+
|
| 68 |
+
Returns:
|
| 69 |
+
str: ๊ตฌ์กฐํ๋ HTML ํ
์คํธ
|
| 70 |
+
"""
|
| 71 |
+
blocks = page.get_text("dict")["blocks"]
|
| 72 |
+
html_text = []
|
| 73 |
+
|
| 74 |
+
for block in blocks:
|
| 75 |
+
if block["type"] == 0: # ํ
์คํธ ๋ธ๋ก
|
| 76 |
+
text_lines = []
|
| 77 |
+
for line in block["lines"]:
|
| 78 |
+
line_text = ""
|
| 79 |
+
for span in line["spans"]:
|
| 80 |
+
# ํฐํธ ํฌ๊ธฐ์ ์คํ์ผ ๋ถ์
|
| 81 |
+
font_size = span["size"]
|
| 82 |
+
is_bold = "bold" in span["font"].lower() or span.get("flags", 0) & 16 != 0
|
| 83 |
+
is_italic = "italic" in span["font"].lower() or span.get("flags", 0) & 1 != 0
|
| 84 |
+
|
| 85 |
+
text = span["text"]
|
| 86 |
+
|
| 87 |
+
# ํฐํธ ํฌ๊ธฐ์ ๋ฐ๋ผ ์ ๋ชฉ ๋๋ ์ผ๋ฐ ํ
์คํธ๋ก ๋ถ๋ฅ
|
| 88 |
+
if font_size > 14: # ํฐ ํฐํธ๋ ์ ๋ชฉ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์
|
| 89 |
+
if is_bold:
|
| 90 |
+
text = f"<h1>{text}</h1>"
|
| 91 |
+
else:
|
| 92 |
+
text = f"<h2>{text}</h2>"
|
| 93 |
+
elif font_size > 12:
|
| 94 |
+
if is_bold:
|
| 95 |
+
text = f"<h3>{text}</h3>"
|
| 96 |
+
else:
|
| 97 |
+
text = f"<h4>{text}</h4>"
|
| 98 |
+
else:
|
| 99 |
+
if is_bold:
|
| 100 |
+
text = f"<strong>{text}</strong>"
|
| 101 |
+
if is_italic:
|
| 102 |
+
text = f"<em>{text}</em>"
|
| 103 |
+
|
| 104 |
+
line_text += text
|
| 105 |
+
|
| 106 |
+
text_lines.append(line_text)
|
| 107 |
+
|
| 108 |
+
# ํ
์คํธ ๋ผ์ธ์ ๋จ๋ฝ์ผ๋ก ๊ฒฐํฉ
|
| 109 |
+
if text_lines:
|
| 110 |
+
paragraph = " ".join(text_lines)
|
| 111 |
+
html_text.append(f"<p>{paragraph}</p>")
|
| 112 |
+
|
| 113 |
+
return "\n".join(html_text)
|
| 114 |
+
|
| 115 |
+
def _extract_images(self, page, page_num):
|
| 116 |
+
"""
|
| 117 |
+
ํ์ด์ง์์ ์ด๋ฏธ์ง ์ถ์ถ
|
| 118 |
+
|
| 119 |
+
Args:
|
| 120 |
+
page (fitz.Page): PDF ํ์ด์ง ๊ฐ์ฒด
|
| 121 |
+
page_num (int): ํ์ด์ง ๋ฒํธ
|
| 122 |
+
|
| 123 |
+
Returns:
|
| 124 |
+
list: ์ด๋ฏธ์ง HTML ํ๊ทธ ๋ชฉ๋ก
|
| 125 |
+
"""
|
| 126 |
+
image_tags = []
|
| 127 |
+
image_list = page.get_images(full=True)
|
| 128 |
+
|
| 129 |
+
for img_idx, img_info in enumerate(image_list):
|
| 130 |
+
try:
|
| 131 |
+
xref = img_info[0]
|
| 132 |
+
base_img = self.doc.extract_image(xref)
|
| 133 |
+
image_bytes = base_img["image"]
|
| 134 |
+
|
| 135 |
+
# ์ด๋ฏธ์ง ํฌ๋งท ํ์ธ (๊ธฐ๋ณธ๊ฐ์ png)
|
| 136 |
+
image_ext = base_img["ext"]
|
| 137 |
+
if image_ext.lower() not in ["jpeg", "jpg", "png"]:
|
| 138 |
+
image_ext = "png"
|
| 139 |
+
|
| 140 |
+
# ๊ณ ์ ๋ ๊ฒฝ๋ก์ ์ด๋ฏธ์ง ์ ์ฅ
|
| 141 |
+
image_filename = f"page{page_num+1}_img{img_idx+1}.{image_ext}"
|
| 142 |
+
image_path = self.img_dir / image_filename
|
| 143 |
+
|
| 144 |
+
# ์ด๋ฏธ์ง ๋๋ ํ ๋ฆฌ ํ์ธ
|
| 145 |
+
if not self.img_dir.exists():
|
| 146 |
+
self.img_dir.mkdir(parents=True, exist_ok=True)
|
| 147 |
+
|
| 148 |
+
with open(image_path, "wb") as img_file:
|
| 149 |
+
img_file.write(image_bytes)
|
| 150 |
+
|
| 151 |
+
# ๋๋ฒ๊น
์ ์ํ ์ฝ๋
|
| 152 |
+
print(f"์ด๋ฏธ์ง ์ ์ฅ: {image_path} (ํฌ๊ธฐ: {len(image_bytes)} ๋ฐ์ดํธ)")
|
| 153 |
+
|
| 154 |
+
# ์ด๋ฏธ์ง ํ๊ทธ ์์ฑ (์๋ ๊ฒฝ๋ก ์ฌ์ฉ)
|
| 155 |
+
# ๊ฒฝ๋ก๊ฐ HTML ํ์ผ์์ ์ฌ๋ฐ๋ฅด๊ฒ ์ฐธ์กฐ๋ ์ ์๋๋ก ํฉ๋๋ค
|
| 156 |
+
rel_img_path = f"images/{image_filename}"
|
| 157 |
+
img_tag = f'<div class="image-container"><img src="{rel_img_path}" alt="Page {page_num+1} Image {img_idx+1}" style="max-width:100%; height:auto;"/></div>'
|
| 158 |
+
image_tags.append(img_tag)
|
| 159 |
+
|
| 160 |
+
except Exception as e:
|
| 161 |
+
print(f"์ด๋ฏธ์ง ์ถ์ถ ์ค ์ค๋ฅ: {str(e)}")
|
| 162 |
+
|
| 163 |
+
return image_tags
|
| 164 |
+
|
| 165 |
+
def _extract_tables(self, page):
|
| 166 |
+
"""
|
| 167 |
+
ํ์ด์ง์์ ํ ์ถ์ถ ์๋
|
| 168 |
+
|
| 169 |
+
Args:
|
| 170 |
+
page (fitz.Page): PDF ํ์ด์ง ๊ฐ์ฒด
|
| 171 |
+
|
| 172 |
+
Returns:
|
| 173 |
+
list: ํ HTML ํ๊ทธ ๋ชฉ๋ก
|
| 174 |
+
"""
|
| 175 |
+
# ํ ๊ฐ์ง ๋ฐ ์ถ์ถ์ ๋ณต์กํ ์์
์
๋๋ค.
|
| 176 |
+
# ์ด ๊ฐ๋จํ ์์์์๋ ํ
์ด๋ธ๋ก ๋ณด์ด๋ ๊ตฌ์กฐ๋ฅผ ๊ฐ์งํ๋ ๊ธฐ๋ณธ์ ์ธ ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํฉ๋๋ค.
|
| 177 |
+
tables = []
|
| 178 |
+
|
| 179 |
+
# ํ์ด์ง์ ํ
์คํธ ๋ธ๋ก์ ๋ถ์
|
| 180 |
+
blocks = page.get_text("dict")["blocks"]
|
| 181 |
+
|
| 182 |
+
# ๋์ด๊ฐ ๋น์ทํ ํ
์คํธ ๋ธ๋ก์ด ๊ฐ๋ก๋ก ์ ๋ ฌ๋ ๊ฒฝ์ฐ ํ
์ด๋ธ ํ์ผ ๊ฐ๋ฅ์ฑ์ด ์์
|
| 183 |
+
table_candidates = []
|
| 184 |
+
|
| 185 |
+
for i, block in enumerate(blocks):
|
| 186 |
+
if block["type"] == 0: # ํ
์คํธ ๋ธ๋ก
|
| 187 |
+
# ํ
์คํธ ๋ธ๋ก์ ์์น ์ ๋ณด
|
| 188 |
+
x0, y0, x1, y1 = block["bbox"]
|
| 189 |
+
|
| 190 |
+
# ๊ฐ์ ํ์ ์๋ ๋ค๋ฅธ ํ
์คํธ ๋ธ๋ก ์ฐพ๊ธฐ
|
| 191 |
+
same_row_blocks = []
|
| 192 |
+
|
| 193 |
+
for j, other_block in enumerate(blocks):
|
| 194 |
+
if i != j and other_block["type"] == 0:
|
| 195 |
+
ox0, oy0, ox1, oy1 = other_block["bbox"]
|
| 196 |
+
|
| 197 |
+
# y ์ขํ๊ฐ ๋น์ทํ๋ฉด ๊ฐ์ ํ์ผ ๊ฐ๋ฅ์ฑ์ด ์์
|
| 198 |
+
if abs(y0 - oy0) < 5 and abs(y1 - oy1) < 5:
|
| 199 |
+
same_row_blocks.append(j)
|
| 200 |
+
|
| 201 |
+
# ๊ฐ์ ํ์ ์ฌ๋ฌ ํ
์คํธ ๋ธ๋ก์ด ์์ผ๋ฉด ํ
์ด๋ธ ํ์ผ ๊ฐ๋ฅ์ฑ์ด ๋์
|
| 202 |
+
if len(same_row_blocks) >= 2:
|
| 203 |
+
table_candidates.append((i, same_row_blocks))
|
| 204 |
+
|
| 205 |
+
# ํ
์ด๋ธ ํ๋ณด๊ฐ ์์ผ๋ฉด HTML ํ
์ด๋ธ๋ก ๋ณํ
|
| 206 |
+
if table_candidates:
|
| 207 |
+
table_html = "<table border='1'>\n"
|
| 208 |
+
|
| 209 |
+
for row_idx, row_blocks in table_candidates:
|
| 210 |
+
table_html += "<tr>\n"
|
| 211 |
+
|
| 212 |
+
# ํ์ฌ ๋ธ๋ก ์ถ๊ฐ
|
| 213 |
+
block_text = ""
|
| 214 |
+
for line in blocks[row_idx]["lines"]:
|
| 215 |
+
for span in line["spans"]:
|
| 216 |
+
block_text += span["text"] + " "
|
| 217 |
+
|
| 218 |
+
table_html += f"<td>{block_text.strip()}</td>\n"
|
| 219 |
+
|
| 220 |
+
# ๊ฐ์ ํ์ ๋ค๋ฅธ ๋ธ๋ก ์ถ๊ฐ
|
| 221 |
+
for block_idx in row_blocks:
|
| 222 |
+
block_text = ""
|
| 223 |
+
for line in blocks[block_idx]["lines"]:
|
| 224 |
+
for span in line["spans"]:
|
| 225 |
+
block_text += span["text"] + " "
|
| 226 |
+
|
| 227 |
+
table_html += f"<td>{block_text.strip()}</td>\n"
|
| 228 |
+
|
| 229 |
+
table_html += "</tr>\n"
|
| 230 |
+
|
| 231 |
+
table_html += "</table>"
|
| 232 |
+
tables.append(table_html)
|
| 233 |
+
|
| 234 |
+
return tables
|
| 235 |
+
|
| 236 |
+
def _create_html_template(self, title, content, css_additional=""):
|
| 237 |
+
"""
|
| 238 |
+
HTML ํ
ํ๋ฆฟ ์์ฑ - ๋คํฌ ํ
๋ง ์ ์ฉ
|
| 239 |
+
|
| 240 |
+
Args:
|
| 241 |
+
title (str): HTML ์ ๋ชฉ
|
| 242 |
+
content (str): HTML ๋ณธ๋ฌธ ๋ด์ฉ
|
| 243 |
+
css_additional (str): ์ถ๊ฐ CSS ์คํ์ผ
|
| 244 |
+
|
| 245 |
+
Returns:
|
| 246 |
+
str: ์์ฑ๋ HTML ๋ฌธ์์ด
|
| 247 |
+
"""
|
| 248 |
+
return f"""<!DOCTYPE html>
|
| 249 |
+
<html lang="ko">
|
| 250 |
+
<head>
|
| 251 |
+
<meta charset="UTF-8">
|
| 252 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 253 |
+
<title>{title}</title>
|
| 254 |
+
<style>
|
| 255 |
+
body {{
|
| 256 |
+
font-family: Arial, sans-serif;
|
| 257 |
+
line-height: 1.6;
|
| 258 |
+
margin: 0;
|
| 259 |
+
padding: 0;
|
| 260 |
+
height: 100vh;
|
| 261 |
+
overflow-y: auto;
|
| 262 |
+
background-color: #2a2a2a;
|
| 263 |
+
color: #ffffff;
|
| 264 |
+
}}
|
| 265 |
+
.page-title {{
|
| 266 |
+
padding: 10px 20px;
|
| 267 |
+
margin: 0;
|
| 268 |
+
background-color: #333;
|
| 269 |
+
color: white;
|
| 270 |
+
position: sticky;
|
| 271 |
+
top: 0;
|
| 272 |
+
z-index: 10;
|
| 273 |
+
}}
|
| 274 |
+
.content-container {{
|
| 275 |
+
padding: 20px;
|
| 276 |
+
}}
|
| 277 |
+
.image-container {{
|
| 278 |
+
text-align: center;
|
| 279 |
+
margin: 20px 0;
|
| 280 |
+
}}
|
| 281 |
+
img {{
|
| 282 |
+
max-width: 100%;
|
| 283 |
+
height: auto;
|
| 284 |
+
border: 1px solid #444;
|
| 285 |
+
}}
|
| 286 |
+
table {{
|
| 287 |
+
border-collapse: collapse;
|
| 288 |
+
width: 100%;
|
| 289 |
+
margin: 20px 0;
|
| 290 |
+
background-color: #333;
|
| 291 |
+
}}
|
| 292 |
+
td, th {{
|
| 293 |
+
border: 1px solid #555;
|
| 294 |
+
padding: 8px;
|
| 295 |
+
color: #fff;
|
| 296 |
+
}}
|
| 297 |
+
h1, h2, h3, h4, p, span, div {{
|
| 298 |
+
color: #fff;
|
| 299 |
+
}}
|
| 300 |
+
.media-item {{
|
| 301 |
+
margin-bottom: 30px;
|
| 302 |
+
padding-bottom: 20px;
|
| 303 |
+
border-bottom: 1px solid #444;
|
| 304 |
+
}}
|
| 305 |
+
.media-item-heading {{
|
| 306 |
+
background-color: #444;
|
| 307 |
+
padding: 5px 10px;
|
| 308 |
+
margin-bottom: 10px;
|
| 309 |
+
font-weight: bold;
|
| 310 |
+
border-left: 3px solid #E67E22;
|
| 311 |
+
color: #fff;
|
| 312 |
+
}}
|
| 313 |
+
.page-text {{
|
| 314 |
+
margin-bottom: 30px;
|
| 315 |
+
border-bottom: 1px solid #444;
|
| 316 |
+
padding-bottom: 20px;
|
| 317 |
+
}}
|
| 318 |
+
/* ์คํฌ๋กค๋ฐ ์คํ์ผ */
|
| 319 |
+
::-webkit-scrollbar {{
|
| 320 |
+
width: 8px;
|
| 321 |
+
}}
|
| 322 |
+
::-webkit-scrollbar-track {{
|
| 323 |
+
background: #333;
|
| 324 |
+
}}
|
| 325 |
+
::-webkit-scrollbar-thumb {{
|
| 326 |
+
background: #666;
|
| 327 |
+
border-radius: 4px;
|
| 328 |
+
}}
|
| 329 |
+
::-webkit-scrollbar-thumb:hover {{
|
| 330 |
+
background: #777;
|
| 331 |
+
}}
|
| 332 |
+
/* ๋งํฌ ์คํ์ผ */
|
| 333 |
+
a {{
|
| 334 |
+
color: #3498db;
|
| 335 |
+
text-decoration: none;
|
| 336 |
+
}}
|
| 337 |
+
a:hover {{
|
| 338 |
+
text-decoration: underline;
|
| 339 |
+
}}
|
| 340 |
+
{css_additional}
|
| 341 |
+
</style>
|
| 342 |
+
</head>
|
| 343 |
+
<body>
|
| 344 |
+
<h1 class="page-title">{title}</h1>
|
| 345 |
+
<div class="content-container">
|
| 346 |
+
{content}
|
| 347 |
+
</div>
|
| 348 |
+
</body>
|
| 349 |
+
</html>"""
|
| 350 |
+
|
| 351 |
+
def convert(self):
|
| 352 |
+
"""
|
| 353 |
+
PDF๋ฅผ ํ
์คํธ HTML๊ณผ ๋ฏธ๋์ด HTML๋ก ๋ถ๋ฆฌํ์ฌ ๋ณํ
|
| 354 |
+
|
| 355 |
+
Returns:
|
| 356 |
+
tuple: ํ
์คํธ HTML ๊ฒฝ๋ก, ๋ฏธ๋์ด HTML ๊ฒฝ๋ก
|
| 357 |
+
"""
|
| 358 |
+
# ํ
์คํธ ์ปฌ๋ผ๊ณผ ๋ฏธ๋์ด ์ปฌ๋ผ์ ์ํ ์ปจํ
์ธ ์ค๋น
|
| 359 |
+
text_content = []
|
| 360 |
+
media_content = []
|
| 361 |
+
media_order = 0 # ๋ฏธ๋์ด ์์ดํ
์์
|
| 362 |
+
|
| 363 |
+
# ๊ฐ ํ์ด์ง ์ฒ๋ฆฌ
|
| 364 |
+
for page_num, page in enumerate(self.doc):
|
| 365 |
+
# ํ
์คํธ ์ถ์ถ
|
| 366 |
+
text_html = self._extract_text_with_structure(page)
|
| 367 |
+
text_content.append(f"\n<div class='page-text' id='page-text-{page_num+1}'>\n")
|
| 368 |
+
text_content.append(f"<h3>ํ์ด์ง {page_num+1}</h3>")
|
| 369 |
+
text_content.append(text_html)
|
| 370 |
+
text_content.append("\n</div>\n")
|
| 371 |
+
|
| 372 |
+
# ํ ์ถ์ถ
|
| 373 |
+
tables = self._extract_tables(page)
|
| 374 |
+
for table_idx, table in enumerate(tables):
|
| 375 |
+
media_order += 1
|
| 376 |
+
media_content.append(f"""
|
| 377 |
+
<div class="media-item" id="table-{page_num+1}-{table_idx+1}" data-page="{page_num+1}">
|
| 378 |
+
<div class="media-item-heading">ํ {media_order} - ํ์ด์ง {page_num+1}</div>
|
| 379 |
+
{table}
|
| 380 |
+
</div>
|
| 381 |
+
""")
|
| 382 |
+
|
| 383 |
+
# ์ด๋ฏธ์ง ์ถ์ถ
|
| 384 |
+
images = self._extract_images(page, page_num)
|
| 385 |
+
for img_idx, img_tag in enumerate(images):
|
| 386 |
+
media_order += 1
|
| 387 |
+
media_content.append(f"""
|
| 388 |
+
<div class="media-item" id="image-{page_num+1}-{img_idx+1}" data-page="{page_num+1}">
|
| 389 |
+
<div class="media-item-heading">์ด๋ฏธ์ง {media_order} - ํ์ด์ง {page_num+1}</div>
|
| 390 |
+
{img_tag}
|
| 391 |
+
</div>
|
| 392 |
+
""")
|
| 393 |
+
|
| 394 |
+
# ํ
์คํธ HTML ์์ฑ
|
| 395 |
+
text_html_content = self._create_html_template(
|
| 396 |
+
f"{self.pdf_name} - ํ
์คํธ",
|
| 397 |
+
"\n".join(text_content)
|
| 398 |
+
)
|
| 399 |
+
|
| 400 |
+
# ๋ฏธ๋์ด HTML ์์ฑ
|
| 401 |
+
media_html_content = self._create_html_template(
|
| 402 |
+
f"{self.pdf_name} - ํ ๋ฐ ์ด๋ฏธ์ง",
|
| 403 |
+
"\n".join(media_content)
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
# ํ
์คํธ HTML ํ์ผ ์ ์ฅ
|
| 407 |
+
text_output_path = self.output_dir / "text.html"
|
| 408 |
+
with open(text_output_path, "w", encoding="utf-8") as html_file:
|
| 409 |
+
html_file.write(text_html_content)
|
| 410 |
+
|
| 411 |
+
# ๋ฏธ๋์ด HTML ํ์ผ ์ ์ฅ
|
| 412 |
+
media_output_path = self.output_dir / "media.html"
|
| 413 |
+
with open(media_output_path, "w", encoding="utf-8") as html_file:
|
| 414 |
+
html_file.write(media_html_content)
|
| 415 |
+
|
| 416 |
+
# ๊ฒฐ๊ณผ ์ ์ฅ
|
| 417 |
+
self.text_html_content = text_html_content
|
| 418 |
+
self.media_html_content = media_html_content
|
| 419 |
+
|
| 420 |
+
return str(text_output_path), str(media_output_path)
|
poetry.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.poetry]
|
| 2 |
+
name = "pdf2html"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = ""
|
| 5 |
+
authors = ["jrpark <jrpark@petobio.com>"]
|
| 6 |
+
readme = "README.md"
|
| 7 |
+
|
| 8 |
+
[tool.poetry.dependencies]
|
| 9 |
+
python = "^3.13"
|
| 10 |
+
pymupdf = "^1.25.3"
|
| 11 |
+
beautifulsoup4 = "^4.13.3"
|
| 12 |
+
langchain = "^0.3.20"
|
| 13 |
+
gradio = "^5.20.1"
|
| 14 |
+
gradio-pdf = "^0.0.22"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
[tool.poetry.group.dev.dependencies]
|
| 18 |
+
ipykernel = "^6.29.5"
|
| 19 |
+
|
| 20 |
+
[build-system]
|
| 21 |
+
requires = ["poetry-core"]
|
| 22 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PyMuPDF==1.25.3
|
| 2 |
+
beautifulsoup4==4.13.3
|
| 3 |
+
langchain==0.3.20
|
| 4 |
+
gradio==5.20.1
|
| 5 |
+
gradio-pdf==0.0.22
|
static/page11_img1.png
ADDED
|
Git LFS Details
|
static/page16_img1.png
ADDED
|
Git LFS Details
|
static/page2_img1.png
ADDED
|
Git LFS Details
|
static/page3_img1.png
ADDED
|
Git LFS Details
|
static/page4_img1.png
ADDED
|
Git LFS Details
|
static/page7_img1.png
ADDED
|
Git LFS Details
|
test.ipynb
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"```mermaid\n",
|
| 8 |
+
"graph TD\n",
|
| 9 |
+
" A[LLM in Veterinary] --> B[ํ๋กฌํํธ ์์ง๋์ด๋ง]\n",
|
| 10 |
+
" A --> C[ํ์ธํ๋]\n",
|
| 11 |
+
" A --> D[ํ๊ฐ ๋ฐฉ๋ฒ]\n",
|
| 12 |
+
" A --> E[์ค์ฆ ์ฌ๋ก]\n",
|
| 13 |
+
" A --> F[๋ฉํฐ๋ชจ๋ฌ]\n",
|
| 14 |
+
" \n",
|
| 15 |
+
" B --> B1(Structured Prompt)\n",
|
| 16 |
+
" B --> B2(Contextual Guidance)\n",
|
| 17 |
+
" B --> B3(Chain-of-Thought)\n",
|
| 18 |
+
" \n",
|
| 19 |
+
" C --> C1(Alpaca-7B)\n",
|
| 20 |
+
" C --> C2(Data-efficient)\n",
|
| 21 |
+
" C --> C3(SNOMED-CT)\n",
|
| 22 |
+
" \n",
|
| 23 |
+
" D --> D1(MM-Vet)\n",
|
| 24 |
+
" D --> D2(Stratified F1)\n",
|
| 25 |
+
" D --> D3(Exact Match)\n",
|
| 26 |
+
" \n",
|
| 27 |
+
" E --> E1(Diagnosis Coding)\n",
|
| 28 |
+
" E --> E2(Educational GPT)\n",
|
| 29 |
+
" E --> E3(Epidemiological Modeling)\n",
|
| 30 |
+
" \n",
|
| 31 |
+
" F --> F1(VLMs)\n",
|
| 32 |
+
" F --> F2(PyMuPDF4LLM)\n",
|
| 33 |
+
" F --> F3(Medical Imaging)\n",
|
| 34 |
+
"```"
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "markdown",
|
| 39 |
+
"metadata": {},
|
| 40 |
+
"source": [
|
| 41 |
+
"```mermaid\n",
|
| 42 |
+
"mindmap\n",
|
| 43 |
+
" root((์์ํ ๋ถ์ผ\n",
|
| 44 |
+
" LLM ์ฐ๊ตฌ))\n",
|
| 45 |
+
" ์์ ์ง๋จ ์ง์\n",
|
| 46 |
+
" ์ฆ์ ๊ธฐ๋ฐ ์ง๋ณ ์์ธก\n",
|
| 47 |
+
" ๊ณ ์์ด ํ๋ ๋ถ์\n",
|
| 48 |
+
" ๊ฐ ํผ๋ถ ์งํ ์ง๋จ\n",
|
| 49 |
+
" ์๋ฃ ์์ ๋ถ์\n",
|
| 50 |
+
" ๋ฐฉ์ฌ์ ์์ ํด์\n",
|
| 51 |
+
" ํผ๋ถ ๋ณ๋ณ ์ธ์\n",
|
| 52 |
+
" ์๋ํ๋ ์ง๋จ ์์คํ
\n",
|
| 53 |
+
" ๋ค์ค ์ฆ์ ํตํฉ ๋ถ์\n",
|
| 54 |
+
" ์๋ฃ ๋ฐ์ดํฐ ๋ถ์\n",
|
| 55 |
+
" ์ ์ ์๋ฌด ๊ธฐ๋ก ๋ถ์\n",
|
| 56 |
+
" ์น๋ฃ ํจํด ๋ฐ๊ฒฌ\n",
|
| 57 |
+
" ์น๋ฃ ํจ๊ณผ ์์ธก\n",
|
| 58 |
+
" ์ญํ ๋ฐ์ดํฐ ๋ง์ด๋\n",
|
| 59 |
+
" ์ง๋ณ ๋ฐ์ ํจํด\n",
|
| 60 |
+
" ์ง์ญ ์ ํ ์์ธก\n",
|
| 61 |
+
" ์์ฒด์ ํธ ํด์\n",
|
| 62 |
+
" ์ง์์ ๋ชจ๋ํฐ๋ง ์์คํ
\n",
|
| 63 |
+
" ๋ง์ถคํ ์น๋ฃ ๊ณํ\n",
|
| 64 |
+
" ์ฝ๋ฌผ ์ฒ๋ฐฉ ์ต์ ํ\n",
|
| 65 |
+
" ์ข
ํน์ด์ ์ฉ๋ ์กฐ์ \n",
|
| 66 |
+
" ์ฝ๋ฌผ ์ํธ์์ฉ ์์ธก\n",
|
| 67 |
+
" ์์ ๊ณํ ์ง์\n",
|
| 68 |
+
" 3D ๋ชจ๋ธ๋ง ํตํฉ\n",
|
| 69 |
+
" ์ฌํ ํ๋ก๊ทธ๋จ ์ค๊ณ\n",
|
| 70 |
+
" ๋๋ฌผ ๋ง์ถคํ ์ด๋ ๊ณํ\n",
|
| 71 |
+
" ๊ต์ก ๋ฐ ํ๋ จ\n",
|
| 72 |
+
" ์์ํ ํ์ ๊ต์ก\n",
|
| 73 |
+
" ๊ฐ์ ์ฌ๋ก ์๋ฎฌ๋ ์ด์
\n",
|
| 74 |
+
" ๋ํํ ํ์ต ์์คํ
\n",
|
| 75 |
+
" ์์์ฌ ์ง์ ๊ต์ก\n",
|
| 76 |
+
" ์ต์ ์ฐ๊ตฌ ์์ฝ ์์ฑ\n",
|
| 77 |
+
" ์ง๋จ ์ง์นจ ์
๋ฐ์ดํธ\n",
|
| 78 |
+
" ํ๋กฌํํธ ์์ง๋์ด๋ง\n",
|
| 79 |
+
" ์์ํ ํนํ ํ๋กฌํํธ\n",
|
| 80 |
+
" ํด๋ถํ์ ์ ํ์ฑ ํฅ์\n",
|
| 81 |
+
" ์ข
ํน์ด์ ์ง์ ํตํฉ\n",
|
| 82 |
+
" ๋ค๋จ๊ณ ์ถ๋ก ํ๋กฌํํธ\n",
|
| 83 |
+
" ๋ณต์กํ ์ง๋ณ ์ง๋จ\n",
|
| 84 |
+
" ๋ชจ๋ธ ํ๊ฐ ๋ฐ ๊ฒ์ฆ\n",
|
| 85 |
+
" ์์ ์ ํ๋ ํ๊ฐ\n",
|
| 86 |
+
" ์ ๋ฌธ๊ฐ ๊ฒ์ฆ ๋ฐฉ๋ฒ๋ก \n",
|
| 87 |
+
" ํ์ ๊ฒฐ๊ณผ ์ถ์ ์ฐ๊ตฌ\n",
|
| 88 |
+
" ์ค๋ฆฌ์ ๊ณ ๋ ค์ฌํญ\n",
|
| 89 |
+
" ์์ฌ๊ฒฐ์ ํฌ๋ช
์ฑ\n",
|
| 90 |
+
" ์ค์ง ์ํ ๊ด๋ฆฌ\n",
|
| 91 |
+
" ๋ฉํฐ๋ชจ๋ฌ ์์ฉ\n",
|
| 92 |
+
" ์ด๋ฏธ์ง-ํ
์คํธ ํตํฉ ๋ถ์\n",
|
| 93 |
+
" ๋ฐฉ์ฌ์ ์์ + ์์ ๊ธฐ๋ก\n",
|
| 94 |
+
" ํ๋ฏธ๊ฒฝ ์์ + ํ์ก ๊ฒ์ฌ\n",
|
| 95 |
+
" ์ค๋์ค ๊ธฐ๋ฐ ์ง๋จ\n",
|
| 96 |
+
" ์ฌ์ฅ ๋ฐ ํ ์๋ฆฌ ๋ถ์\n",
|
| 97 |
+
" ๋๋ฌผ ๋ฐ์ฑ ํด์\n",
|
| 98 |
+
" ํ์ ๊ฐ ์ฐ๊ตฌ\n",
|
| 99 |
+
" ์ํฌ์ค ์ ๊ทผ๋ฒ\n",
|
| 100 |
+
" ์ธ์๊ณตํต ์ง๋ณ ๊ฐ์\n",
|
| 101 |
+
" ํ๊ฒฝ-๋๋ฌผ-์ธ๊ฐ ์ํธ์์ฉ\n",
|
| 102 |
+
" ์ผ์๋๋ฌผ ๋ณด์ ์์ฉ\n",
|
| 103 |
+
" ํ๋ณธ ๋ชจ๋ํฐ๋ง ์๋ํ\n",
|
| 104 |
+
" ๋ฉธ์ข
์๊ธฐ์ข
๋ณดํธ ์ ๋ต\n",
|
| 105 |
+
"```"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"cell_type": "code",
|
| 110 |
+
"execution_count": null,
|
| 111 |
+
"metadata": {},
|
| 112 |
+
"outputs": [],
|
| 113 |
+
"source": []
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"cell_type": "code",
|
| 117 |
+
"execution_count": null,
|
| 118 |
+
"metadata": {},
|
| 119 |
+
"outputs": [],
|
| 120 |
+
"source": []
|
| 121 |
+
}
|
| 122 |
+
],
|
| 123 |
+
"metadata": {
|
| 124 |
+
"kernelspec": {
|
| 125 |
+
"display_name": ".venv",
|
| 126 |
+
"language": "python",
|
| 127 |
+
"name": "python3"
|
| 128 |
+
},
|
| 129 |
+
"language_info": {
|
| 130 |
+
"name": "python",
|
| 131 |
+
"version": "3.13.1"
|
| 132 |
+
}
|
| 133 |
+
},
|
| 134 |
+
"nbformat": 4,
|
| 135 |
+
"nbformat_minor": 2
|
| 136 |
+
}
|
web_interface.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
import base64
|
| 5 |
+
|
| 6 |
+
# PDF to HTML ๋ณํ๊ธฐ ํด๋์ค ์ํฌํธ - ์์ ๋ ๋ฒ์ ์ฌ์ฉ
|
| 7 |
+
from convert import PDFToHTMLConverter
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def convert_pdf_to_html(pdf_file):
|
| 11 |
+
"""PDF ํ์ผ์ HTML๋ก ๋ณํํ๊ณ ๊ฒฐ๊ณผ ๋ฐํ"""
|
| 12 |
+
try:
|
| 13 |
+
# ํ์ฌ ์์
๋๋ ํ ๋ฆฌ ํ์ธ
|
| 14 |
+
current_dir = Path.cwd()
|
| 15 |
+
temp_dir = current_dir / ".temp"
|
| 16 |
+
|
| 17 |
+
# PDF ๋ฐ์ดํฐ ์ค๋น
|
| 18 |
+
if hasattr(pdf_file, "name"): # Gradio ํ์ผ ๊ฐ์ฒด์ธ ๊ฒฝ์ฐ
|
| 19 |
+
with open(pdf_file.name, "rb") as f:
|
| 20 |
+
pdf_data = f.read()
|
| 21 |
+
else: # ์ด๋ฏธ ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ์ธ ๊ฒฝ์ฐ
|
| 22 |
+
pdf_data = pdf_file
|
| 23 |
+
|
| 24 |
+
# ๊ณ ์ ๊ฒฝ๋ก์ PDF ์ ์ฅ
|
| 25 |
+
pdf_input_dir = temp_dir / "temp_input_pdf"
|
| 26 |
+
pdf_input_dir.mkdir(exist_ok=True, parents=True)
|
| 27 |
+
pdf_path = pdf_input_dir / "current.pdf"
|
| 28 |
+
|
| 29 |
+
# PDF ์ ์ฅ
|
| 30 |
+
with open(pdf_path, "wb") as f:
|
| 31 |
+
f.write(pdf_data)
|
| 32 |
+
|
| 33 |
+
print(f"PDF ์ ์ฅ ์๋ฃ: {pdf_path}")
|
| 34 |
+
|
| 35 |
+
# PDF ๋ณํ - ํ
์คํธ HTML๊ณผ ๋ฏธ๋์ด HTML๋ก ๋ถ๋ฆฌ
|
| 36 |
+
converter = PDFToHTMLConverter(str(pdf_path))
|
| 37 |
+
text_html_path, media_html_path = converter.convert()
|
| 38 |
+
|
| 39 |
+
print(f"HTML ๋ณํ ์๋ฃ: {text_html_path}, {media_html_path}")
|
| 40 |
+
|
| 41 |
+
# HTML ํ์ผ ์ฝ๊ธฐ
|
| 42 |
+
with open(text_html_path, "r", encoding="utf-8") as f:
|
| 43 |
+
text_html_content = f.read()
|
| 44 |
+
|
| 45 |
+
with open(media_html_path, "r", encoding="utf-8") as f:
|
| 46 |
+
media_html_content = f.read()
|
| 47 |
+
|
| 48 |
+
# ์ด๋ฏธ์ง๋ฅผ Base64๋ก ์ธ์ฝ๋ฉํ์ฌ HTML์ ์ง์ ํฌํจ
|
| 49 |
+
img_dir_path = temp_dir / "temp_output_html" / "images"
|
| 50 |
+
if img_dir_path.exists():
|
| 51 |
+
print(f"์ด๋ฏธ์ง ๋๋ ํ ๋ฆฌ ํ์ธ: {img_dir_path}")
|
| 52 |
+
for img_file in img_dir_path.glob("*.*"):
|
| 53 |
+
try:
|
| 54 |
+
rel_path = f"images/{img_file.name}"
|
| 55 |
+
print(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค: {img_file}")
|
| 56 |
+
|
| 57 |
+
# ์ด๋ฏธ์ง ํ์ผ ์ฝ๊ธฐ
|
| 58 |
+
with open(img_file, "rb") as f:
|
| 59 |
+
encoded_string = base64.b64encode(f.read()).decode("utf-8")
|
| 60 |
+
|
| 61 |
+
# ์ด๋ฏธ์ง ํ์
์ ๋ฐ๋ผ MIME ํ์
์ค์
|
| 62 |
+
ext = img_file.suffix.lower()[1:] # .png -> png
|
| 63 |
+
mime_type = {
|
| 64 |
+
"png": "image/png",
|
| 65 |
+
"jpg": "image/jpeg",
|
| 66 |
+
"jpeg": "image/jpeg",
|
| 67 |
+
"gif": "image/gif",
|
| 68 |
+
"svg": "image/svg+xml",
|
| 69 |
+
}.get(ext, "image/png")
|
| 70 |
+
|
| 71 |
+
# Base64 ์ด๋ฏธ์ง URL ์์ฑ
|
| 72 |
+
data_url = f"data:{mime_type};base64,{encoded_string}"
|
| 73 |
+
|
| 74 |
+
# ๋ฏธ๋์ด HTML ๋ด์ฉ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก ๊ต์ฒด
|
| 75 |
+
original_pattern = f'src="{rel_path}"'
|
| 76 |
+
replacement = f'src="{data_url}"'
|
| 77 |
+
|
| 78 |
+
if original_pattern in media_html_content:
|
| 79 |
+
media_html_content = media_html_content.replace(
|
| 80 |
+
original_pattern, replacement
|
| 81 |
+
)
|
| 82 |
+
print(f"์ด๋ฏธ์ง {img_file.name} Base64 ์ธ์ฝ๋ฉ ์๋ฃ")
|
| 83 |
+
else:
|
| 84 |
+
print(
|
| 85 |
+
f"๊ฒฝ๊ณ : ์ด๋ฏธ์ง ๊ฒฝ๋ก '{rel_path}'๋ฅผ HTML์์ ์ฐพ์ ์ ์์ต๋๋ค"
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(f"์ด๋ฏธ์ง {img_file.name} ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
| 90 |
+
else:
|
| 91 |
+
print(f"์ด๋ฏธ์ง ๋๋ ํ ๋ฆฌ๊ฐ ์กด์ฌํ์ง ์์: {img_dir_path}")
|
| 92 |
+
|
| 93 |
+
# ์คํฌ๋กค ๊ฐ๋ฅํ ์ปจํ
์ด๋๋ก HTML ์ปจํ
์ธ ๋ํ
|
| 94 |
+
text_html_with_style = f"""
|
| 95 |
+
<div style="width: 100%; height: 800px; overflow-y: auto; border: 1px solid #444; background-color: #2a2a2a;">
|
| 96 |
+
{text_html_content}
|
| 97 |
+
</div>
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
media_html_with_style = f"""
|
| 101 |
+
<div style="width: 100%; height: 800px; overflow-y: auto; border: 1px solid #444; background-color: #2a2a2a;">
|
| 102 |
+
{media_html_content}
|
| 103 |
+
</div>
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
print("HTML ๋ด์ฉ ์ค๋น ์๋ฃ")
|
| 107 |
+
|
| 108 |
+
# ํ
์คํธ HTML๊ณผ ๋ฏธ๋์ด HTML ๋ฐํ
|
| 109 |
+
return text_html_with_style, media_html_with_style
|
| 110 |
+
|
| 111 |
+
except Exception as e:
|
| 112 |
+
import traceback
|
| 113 |
+
|
| 114 |
+
error_details = traceback.format_exc()
|
| 115 |
+
print(f"์ค๋ฅ ๋ฐ์: {str(e)}\n{error_details}")
|
| 116 |
+
error_html = f"<h1>์ค๋ฅ ๋ฐ์</h1><p>{str(e)}</p><pre>{error_details}</pre>"
|
| 117 |
+
return error_html, error_html
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def launch_web_interface():
|
| 121 |
+
"""Gradio ์น ์ธํฐํ์ด์ค ์คํ"""
|
| 122 |
+
# CSS ์คํ์ผ
|
| 123 |
+
css = """
|
| 124 |
+
/* ์ ์ฒด ๋ ์ด์์ */
|
| 125 |
+
body, .gradio-container {
|
| 126 |
+
margin: 0 !important;
|
| 127 |
+
padding: 0 !important;
|
| 128 |
+
width: 100% !important;
|
| 129 |
+
max-width: none !important;
|
| 130 |
+
background-color: #1f1f1f;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
/* ํค๋ ์์ญ */
|
| 134 |
+
.header-area {
|
| 135 |
+
background-color: #2a2a2a;
|
| 136 |
+
padding: 1rem;
|
| 137 |
+
border-bottom: 1px solid #444;
|
| 138 |
+
margin-bottom: 1rem;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/* ์
๋ก๋ ์์ญ */
|
| 142 |
+
.upload-area {
|
| 143 |
+
background-color: #2a2a2a;
|
| 144 |
+
padding: 1rem;
|
| 145 |
+
border-radius: 5px;
|
| 146 |
+
margin-bottom: 1rem;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
/* HTML ๋ทฐ์ด ์ปจํ
์ด๋ */
|
| 150 |
+
.html-columns {
|
| 151 |
+
display: flex;
|
| 152 |
+
gap: 20px;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.html-column {
|
| 156 |
+
flex: 1;
|
| 157 |
+
min-width: 0;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/* HTML ๋ทฐ์ด */
|
| 161 |
+
.html-display {
|
| 162 |
+
min-height: 800px !important;
|
| 163 |
+
width: 100% !important;
|
| 164 |
+
background-color: #2a2a2a !important;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/* HTML ๋ด์ฉ์ ํ
์คํธ ์์ */
|
| 168 |
+
.html-display * {
|
| 169 |
+
color: #ffffff !important;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/* HTML ๋ด์ ํ ์คํ์ผ */
|
| 173 |
+
.html-display table {
|
| 174 |
+
background-color: #333 !important;
|
| 175 |
+
border: 1px solid #555 !important;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
.html-display td,
|
| 179 |
+
.html-display th {
|
| 180 |
+
border: 1px solid #555 !important;
|
| 181 |
+
color: #fff !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/* ๋ฒํผ ์คํ์ผ */
|
| 185 |
+
.convert-button {
|
| 186 |
+
background-color: #E67E22 !important;
|
| 187 |
+
border: none !important;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
/* ํ์ดํ ํ
์คํธ */
|
| 191 |
+
.title-text {
|
| 192 |
+
color: white !important;
|
| 193 |
+
margin: 0 !important;
|
| 194 |
+
padding: 0 !important;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/* ์ค๋ช
ํ
์คํธ */
|
| 198 |
+
.description-text {
|
| 199 |
+
color: #aaa !important;
|
| 200 |
+
margin-top: 0.5rem !important;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
/* ์ปฌ๋ผ ์ ๋ชฉ */
|
| 204 |
+
.column-title {
|
| 205 |
+
color: white !important;
|
| 206 |
+
margin-bottom: 0.5rem !important;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/* ํธํฐ */
|
| 210 |
+
.footer-area {
|
| 211 |
+
margin-top: 2rem;
|
| 212 |
+
text-align: center;
|
| 213 |
+
color: #888;
|
| 214 |
+
padding: 1rem;
|
| 215 |
+
}
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
# Gradio ์ธํฐํ์ด์ค
|
| 219 |
+
with gr.Blocks(css=css, theme=gr.themes.Default()) as demo:
|
| 220 |
+
# ํค๋ ์น์
|
| 221 |
+
with gr.Column(elem_classes="header-area"):
|
| 222 |
+
gr.Markdown("# PDF to HTML ๋ณํ๊ธฐ", elem_classes="title-text")
|
| 223 |
+
gr.Markdown(
|
| 224 |
+
"PDF ํ์ผ์ ์
๋ก๋ํ์ฌ ํ
์คํธ์ ๋ฏธ๋์ด๋ก ๋ถ๋ฆฌ๋ HTML์ ์์ฑํฉ๋๋ค.",
|
| 225 |
+
elem_classes="description-text",
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
# ์
๋ก๋ ์น์
|
| 229 |
+
with gr.Column(elem_classes="upload-area"):
|
| 230 |
+
# ํ์ผ ์
๋ก๋ ๋ฐ ๋ณํ ๋ฒํผ
|
| 231 |
+
with gr.Row():
|
| 232 |
+
pdf_input = gr.File(
|
| 233 |
+
label="PDF ํ์ผ ์
๋ก๋", type="binary", elem_id="pdf-upload"
|
| 234 |
+
)
|
| 235 |
+
convert_btn = gr.Button(
|
| 236 |
+
"๋ณํํ๊ธฐ", variant="primary", elem_classes="convert-button"
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
# ์ํ ํ์
|
| 240 |
+
status_output = gr.Textbox(
|
| 241 |
+
label="์ํ", value="๋๊ธฐ ์ค...", interactive=False
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
+
# HTML ๋ทฐ์ด ์์ญ (๋ ์ด๋ก ๊ตฌ์ฑ)
|
| 245 |
+
with gr.Column(visible=False) as html_output_area:
|
| 246 |
+
with gr.Row(elem_classes="html-columns"):
|
| 247 |
+
# ์ผ์ชฝ ์ด - ํ
์คํธ HTML
|
| 248 |
+
with gr.Column(elem_classes="html-column"):
|
| 249 |
+
gr.Markdown("### ํ
์คํธ ๋ด์ฉ", elem_classes="column-title")
|
| 250 |
+
text_html_viewer = gr.HTML(
|
| 251 |
+
label="ํ
์คํธ HTML",
|
| 252 |
+
elem_id="text-html-viewer",
|
| 253 |
+
elem_classes="html-display",
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# ์ค๋ฅธ์ชฝ ์ด - ๋ฏธ๋์ด HTML
|
| 257 |
+
with gr.Column(elem_classes="html-column"):
|
| 258 |
+
gr.Markdown("### ํ ๋ฐ ์ด๋ฏธ์ง", elem_classes="column-title")
|
| 259 |
+
media_html_viewer = gr.HTML(
|
| 260 |
+
label="๋ฏธ๋์ด HTML",
|
| 261 |
+
elem_id="media-html-viewer",
|
| 262 |
+
elem_classes="html-display",
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
# ํธํฐ
|
| 266 |
+
with gr.Column(elem_classes="footer-area"):
|
| 267 |
+
gr.Markdown("ยฉ 2025 pdf2html")
|
| 268 |
+
|
| 269 |
+
# ๋ณํ ์ฒ๋ฆฌ ํจ์
|
| 270 |
+
def process_conversion(pdf_file):
|
| 271 |
+
if pdf_file is None:
|
| 272 |
+
return (
|
| 273 |
+
gr.update(visible=False),
|
| 274 |
+
"<h1 style='color:white;'>PDF ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์</h1>",
|
| 275 |
+
"<h1 style='color:white;'>PDF ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์</h1>",
|
| 276 |
+
"PDF ํ์ผ์ด ์
๋ก๋๋์ง ์์์ต๋๋ค.",
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
try:
|
| 280 |
+
# ๋ณํ ํจ์ ํธ์ถ
|
| 281 |
+
text_html, media_html = convert_pdf_to_html(pdf_file)
|
| 282 |
+
|
| 283 |
+
# HTML ๋ด์ฉ ๋๋ฒ๊น
|
| 284 |
+
print(f"ํ
์คํธ HTML ๊ธธ์ด: {len(text_html)} ๋ฐ์ดํธ")
|
| 285 |
+
print(f"๋ฏธ๋์ด HTML ๊ธธ์ด: {len(media_html)} ๋ฐ์ดํธ")
|
| 286 |
+
|
| 287 |
+
# HTML ํ์ ์์ญ ๋ณด์ด๊ธฐ ๋ฐ ๋ด์ฉ ์
๋ฐ์ดํธ
|
| 288 |
+
return gr.update(visible=True), text_html, media_html, "๋ณํ ์๋ฃ!"
|
| 289 |
+
except Exception as e:
|
| 290 |
+
import traceback
|
| 291 |
+
|
| 292 |
+
error_details = traceback.format_exc()
|
| 293 |
+
print(f"์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}\n{error_details}")
|
| 294 |
+
error_html = f"<h1 style='color:red;'>์ค๋ฅ ๋ฐ์</h1><p style='color:red;'>{str(e)}</p>"
|
| 295 |
+
return (
|
| 296 |
+
gr.update(visible=False),
|
| 297 |
+
error_html,
|
| 298 |
+
error_html,
|
| 299 |
+
f"์ค๋ฅ: {str(e)}",
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
# ๋ณํ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
| 303 |
+
convert_btn.click(
|
| 304 |
+
fn=process_conversion,
|
| 305 |
+
inputs=pdf_input,
|
| 306 |
+
outputs=[
|
| 307 |
+
html_output_area,
|
| 308 |
+
text_html_viewer,
|
| 309 |
+
media_html_viewer,
|
| 310 |
+
status_output,
|
| 311 |
+
],
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
# ๋ ์ด์์ ๋ฌธ์ ํด๊ฒฐ์ ์ํ JavaScript
|
| 315 |
+
demo.load(
|
| 316 |
+
js="""
|
| 317 |
+
function fixLayout() {
|
| 318 |
+
// HTML ๋ทฐ์ด ์ปจํ
์ด๋ ํ์ธ
|
| 319 |
+
const htmlColumns = document.querySelector('.html-columns');
|
| 320 |
+
if (htmlColumns) {
|
| 321 |
+
// ์ปจํ
์ด๋์ ๋๋น ๊ท ๋ฑํ๊ฒ ๋ง์ถ๊ธฐ
|
| 322 |
+
const columns = htmlColumns.querySelectorAll('.html-column');
|
| 323 |
+
columns.forEach(column => {
|
| 324 |
+
column.style.flex = '1';
|
| 325 |
+
column.style.minWidth = '0';
|
| 326 |
+
});
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// ํ
์คํธ ์์ ๊ฐ์ ์ค์
|
| 330 |
+
const textViewer = document.getElementById('text-html-viewer');
|
| 331 |
+
const mediaViewer = document.getElementById('media-html-viewer');
|
| 332 |
+
|
| 333 |
+
function forceTextColor(element) {
|
| 334 |
+
if (!element) return;
|
| 335 |
+
|
| 336 |
+
// iframe ๋ด๋ถ ๋ฌธ์์ ์ ๊ทผ
|
| 337 |
+
try {
|
| 338 |
+
const iframes = element.querySelectorAll('iframe');
|
| 339 |
+
iframes.forEach(iframe => {
|
| 340 |
+
if (iframe.contentDocument) {
|
| 341 |
+
const allElements = iframe.contentDocument.querySelectorAll('*');
|
| 342 |
+
allElements.forEach(el => {
|
| 343 |
+
if (el.tagName !== 'IMG') {
|
| 344 |
+
el.style.color = '#ffffff';
|
| 345 |
+
}
|
| 346 |
+
});
|
| 347 |
+
|
| 348 |
+
// ๋ฐฐ๊ฒฝ์ ์ค์
|
| 349 |
+
const body = iframe.contentDocument.body;
|
| 350 |
+
if (body) {
|
| 351 |
+
body.style.backgroundColor = '#2a2a2a';
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
});
|
| 355 |
+
} catch (e) {
|
| 356 |
+
console.error('iframe ์ ๊ทผ ์ค ์ค๋ฅ:', e);
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// ์ง์ ๋ฌธ์ ๋ด ์์์ ์์ ์ค์
|
| 360 |
+
const allTextElements = element.querySelectorAll('p, h1, h2, h3, h4, h5, h6, span, div, a, li, td, th');
|
| 361 |
+
allTextElements.forEach(el => {
|
| 362 |
+
el.style.color = '#ffffff';
|
| 363 |
+
});
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
forceTextColor(textViewer);
|
| 367 |
+
forceTextColor(mediaViewer);
|
| 368 |
+
|
| 369 |
+
// ์ด๋ฏธ์ง ํ์ ํ์ธ
|
| 370 |
+
if (mediaViewer) {
|
| 371 |
+
const images = mediaViewer.querySelectorAll('img');
|
| 372 |
+
console.log(`๋ฏธ๋์ด ๋ทฐ์ด์์ ์ด๋ฏธ์ง ${images.length}๊ฐ ๋ฐ๊ฒฌ`);
|
| 373 |
+
|
| 374 |
+
images.forEach((img, index) => {
|
| 375 |
+
// ์ด๋ฏธ์ง ๋ก๋ ์ํ ํ์ธ
|
| 376 |
+
console.log(`์ด๋ฏธ์ง ${index + 1} ๋ก๋ ์ํ: ${img.complete ? '์๋ฃ' : '๋ก๋ฉ ์ค'}`);
|
| 377 |
+
if (img.complete && img.naturalWidth === 0) {
|
| 378 |
+
console.log(`์ด๋ฏธ์ง ${index + 1} ๋ก๋ ์คํจ`);
|
| 379 |
+
}
|
| 380 |
+
});
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
// ํ์ด์ง ๋ก๋ ์ ๋ ์ด์์ ์กฐ์
|
| 385 |
+
window.addEventListener('load', function() {
|
| 386 |
+
setTimeout(fixLayout, 1000);
|
| 387 |
+
setTimeout(fixLayout, 3000);
|
| 388 |
+
setTimeout(fixLayout, 5000); // ๋ ๊ธด ์๊ฐ ํ์๋ ํ ๋ฒ ๋ ์คํ
|
| 389 |
+
});
|
| 390 |
+
|
| 391 |
+
// MutationObserver๋ก DOM ๋ณ๊ฒฝ ๊ฐ์ง
|
| 392 |
+
const observer = new MutationObserver(mutations => {
|
| 393 |
+
setTimeout(fixLayout, 500);
|
| 394 |
+
});
|
| 395 |
+
|
| 396 |
+
// ํ์ด์ง ๋ก๋ ํ Observer ์์
|
| 397 |
+
window.addEventListener('load', () => {
|
| 398 |
+
observer.observe(document.body, {
|
| 399 |
+
childList: true,
|
| 400 |
+
subtree: true,
|
| 401 |
+
attributes: true
|
| 402 |
+
});
|
| 403 |
+
|
| 404 |
+
// ์คํ์ผ ์์ ์ง์ ์ถ๊ฐ
|
| 405 |
+
const style = document.createElement('style');
|
| 406 |
+
style.textContent = `
|
| 407 |
+
.html-display * {
|
| 408 |
+
color: #ffffff !important;
|
| 409 |
+
}
|
| 410 |
+
.html-display {
|
| 411 |
+
background-color: #2a2a2a !important;
|
| 412 |
+
}
|
| 413 |
+
`;
|
| 414 |
+
document.head.appendChild(style);
|
| 415 |
+
});
|
| 416 |
+
"""
|
| 417 |
+
)
|
| 418 |
+
|
| 419 |
+
# ์ธํฐํ์ด์ค ์คํ
|
| 420 |
+
demo.launch(share=False, inbrowser=True, show_api=False)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
if __name__ == "__main__":
|
| 424 |
+
launch_web_interface()
|