Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解析后怎么导出MD? #80

Open
Wizarzz opened this issue Aug 2, 2024 · 1 comment
Open

解析后怎么导出MD? #80

Wizarzz opened this issue Aug 2, 2024 · 1 comment

Comments

@Wizarzz
Copy link

Wizarzz commented Aug 2, 2024

解析好后不管是复制md还是json都直接卡死,没找到直接保存的选项

@ohownew
Copy link

ohownew commented Aug 14, 2024

可以自己调接口,读返回的json,解析text和images字段,分别保存。我用python的requests库实现了一下:

import requests

#### api request ####
url = 'http://localhost:8000/parse_document'
file_path = 'test.pdf'

with open(file_path, 'rb') as f:
    files = {'file': f}
    response = requests.post(url, files=files)

result = response.json()

#### save markdown ####
text = result['text']
with open("./parse_results/test.md", "w") as f:
    f.write(text)

#### save images ####
import base64
from PIL import Image
from io import BytesIO

for raw in result['images']:
    raw_decode = base64.b64decode(raw['image'])
    image_name = raw['image_name']
    Image.open(BytesIO(raw_decode)).save(f'./parse_results/{image_name}', 'PNG')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants