PDFTranslate / docs /ko /APIS.md
Ryuichi
Initial deployment
179eccc
|
Raw History Blame Contribute Delete
2.79 kB

이 λ¬Έμ„œλŠ” 였래된 λ¬Έμ„œμž…λ‹ˆλ‹€. μ°Έκ³ ν•˜μ§€ λ§ˆμ‹­μ‹œμ˜€.

λͺ©μ°¨

ν˜„μž¬ ν”„λ‘œμ νŠΈλŠ” 두 κ°€μ§€ μœ ν˜•μ˜ 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 ν”„λ‘œν† μ½œμ„ μ‚¬μš©ν•˜μ—¬ ν”„λ‘œκ·Έλž¨κ³Ό 톡신할 수 μžˆμŠ΅λ‹ˆλ‹€:

  1. λ°±μ—”λ“œ μ„€μΉ˜ 및 μ‹€ν–‰

    pip install pdf2zh_next[backend]
    pdf2zh_next --flask
    pdf2zh_next --celery worker
    
  2. λ‹€μŒκ³Ό 같이 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
      

⬆️ 맨 μœ„λ‘œ 이동


이 νŽ˜μ΄μ§€μ˜ 일뢀 λ‚΄μš©μ€ GPT 에 μ˜ν•΄ λ²ˆμ—­λ˜μ—ˆμœΌλ©° 였λ₯˜κ°€ 포함될 수 μžˆμŠ΅λ‹ˆλ‹€.