Spaces:
Sleeping
Sleeping
|
Download docs/it/APIS.md from ryusaksun/PDFTranslate: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/spaces/ryusaksun/PDFTranslate/resolve/main/docs/it/APIS.md
- Command line
-
hf download hf://spaces/ryusaksun/PDFTranslate/docs/it/APIS.md
-
curl -L -o APIS.md https://huggingface.co/spaces/ryusaksun/PDFTranslate/resolve/main/docs/it/APIS.md
2.67 kB
Questo documento è obsoleto, si prega di non farvi riferimento.
Indice dei contenuti
Il presente progetto supporta due tipi di API, tutti i metodi necessitano di Redis;Python
Poiché pdf2zh è un modulo installato in Python, esponiamo due metodi che altri programmi possono chiamare in qualsiasi script Python.
Ad esempio, se desideri tradurre un documento dall'inglese al cinese utilizzando Google Translate, puoi utilizzare il seguente codice:
from pdf2zh_next import translate, translate_stream
params = {
'lang_in': 'en',
'lang_out': 'zh',
'service': 'google',
'thread': 4,
}
Traduci con i file:
(file_mono, file_dual) = translate(files=['example.pdf'], **params)[0]
Traduci con flusso:
with open('example.pdf', 'rb') as f:
(stream_mono, stream_dual) = translate_stream(stream=f.read(), **params)
HTTP
In un modo più flessibile, puoi comunicare con il programma utilizzando i protocolli HTTP, se:
Installa ed esegui il backend
pip install pdf2zh_next[backend] pdf2zh_next --flask pdf2zh_next --celery workerUtilizza i protocolli HTTP come segue:
Invia un task di traduzione
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"}Controlla lo stato
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a {"info":{"n":13,"total":506},"state":"PROGRESS"}Controlla lo stato (se completato)
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a {"state":"SUCCESS"}Salva il file monolingue
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/mono --output example-mono.pdfSalva il file bilingue
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a/dual --output example-dual.pdfInterrompi se in esecuzione ed elimina il task
curl http://localhost:11008/v1/translate/d9894125-2f4e-45ea-9d93-1a9068d2045a -X DELETE