Spaces:
Sleeping
Download docs/ko/APIS.md from ryusaksun/PDFTranslate: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/spaces/ryusaksun/PDFTranslate/resolve/main/docs/ko/APIS.md
- Command line
-
hf download hf://spaces/ryusaksun/PDFTranslate/docs/ko/APIS.md
-
curl -L -o APIS.md https://huggingface.co/spaces/ryusaksun/PDFTranslate/resolve/main/docs/ko/APIS.md
μ΄ λ¬Έμλ μ€λλ λ¬Έμμ λλ€. μ°Έκ³ νμ§ λ§μμμ€.
λͺ©μ°¨
νμ¬ νλ‘μ νΈλ λ κ°μ§ μ νμ API λ₯Ό μ§μνλ©°, λͺ¨λ λ°©λ²μλ Redis κ° νμν©λλ€;Python
pdf2zh λ Python μ μ€μΉλ λͺ¨λμ΄λ―λ‘, λ€λ₯Έ νλ‘κ·Έλ¨μμ νΈμΆν μ μλ λ κ°μ§ λ©μλλ₯Ό Python μ€ν¬λ¦½νΈμμ μ 곡ν©λλ€.
μλ₯Ό λ€μ΄, Google Translate λ₯Ό μ¬μ©νμ¬ μμ΄ λ¬Έμλ₯Ό μ€κ΅μ΄λ‘ λ²μνλ €λ©΄ λ€μ μ½λλ₯Ό μ¬μ©ν μ μμ΅λλ€:
from pdf2zh_next import translate, translate_stream
params = {
'lang_in': 'en',
'lang_out': 'zh',
'service': 'google',
'thread': 4,
}
νμΌλ‘ λ²μνκΈ°:
(file_mono, file_dual) = translate(files=['example.pdf'], **params)[0]
μ€νΈλ¦ΌμΌλ‘ λ²μνκΈ°
with open('example.pdf', 'rb') as f:
(stream_mono, stream_dual) = translate_stream(stream=f.read(), **params)
HTTP
λ³΄λ€ μ μ°ν λ°©λ²μΌλ‘, λ€μκ³Ό κ°μ κ²½μ° HTTP νλ‘ν μ½μ μ¬μ©νμ¬ νλ‘κ·Έλ¨κ³Ό ν΅μ ν μ μμ΅λλ€:
λ°±μλ μ€μΉ λ° μ€ν
pip install pdf2zh_next[backend] pdf2zh_next --flask pdf2zh_next --celery workerλ€μκ³Ό κ°μ΄ HTTP νλ‘ν μ½ μ¬μ©:
λ²μ μμ μ μΆ
curl http://localhost:11008/v1/translate -F "file=@example.pdf" -F "data={\"lang_in\":\"en\",\"lang_out\":\"zh\",\"service\":\"google\",\"thread\":4}" {"id":"d9894125-2f4e-45ea-9d93-1a9068d2045a"}μ§ν μν νμΈ
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a {"info":{"n":13,"total":506},"state":"PROGRESS"}μ§ν μν νμΈ (μλ£ μ)
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a {"state":"SUCCESS"}λ¨μΌ μΈμ΄ νμΌ μ μ₯
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/mono --output example-mono.pdfμ΄μ€ μΈμ΄ νμΌ μ μ₯
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/dual --output example-dual.pdfμ€ν μ€μΈ κ²½μ° μ€λ¨νκ³ μμ μμ
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a -X DELETE