Spaces:
Sleeping
Sleeping
Fixed some bugs, added dockerfile
Browse files- Dockerfile +24 -0
- gradio_app.py +2 -3
- readme.md +6 -1
- src/translate_any_doc.py +2 -0
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.12-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY fast_align_config ./fast_align_config
|
6 |
+
COPY src ./src
|
7 |
+
COPY okapi-apps_gtk2-linux-x86_64_1.47.0 ./okapi-apps_gtk2-linux-x86_64_1.47.0
|
8 |
+
COPY gradio_app.py .
|
9 |
+
COPY requirements.txt .
|
10 |
+
|
11 |
+
COPY fast_align .
|
12 |
+
COPY atools .
|
13 |
+
|
14 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
15 |
+
RUN python -m spacy download xx_ent_wiki_sm
|
16 |
+
|
17 |
+
RUN apt-get update && \
|
18 |
+
apt-get install libgomp1 && \
|
19 |
+
apt-get install -y openjdk-17-jre-headless
|
20 |
+
|
21 |
+
CMD ["python", "gradio_app.py"]
|
22 |
+
|
23 |
+
# sudo docker build -t document-translator .
|
24 |
+
# docker run -p 7860:7860 --rm -it document-translator
|
gradio_app.py
CHANGED
@@ -33,8 +33,7 @@ with gr.Blocks() as demo:
|
|
33 |
gr.Interface(fn=translator.translate, inputs=["text", "text", "text"], outputs="text")
|
34 |
with gr.Tab("Documents"):
|
35 |
with gr.Row():
|
36 |
-
dropdown1 = gr.Dropdown(label="Source language", choices=["en", "ca"], value=None,
|
37 |
-
interactive=True)
|
38 |
dropdown2 = gr.Dropdown(label="Target language", choices=["en", "ca"], value=None, interactive=True)
|
39 |
gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
|
40 |
with gr.Row():
|
@@ -44,4 +43,4 @@ with gr.Blocks() as demo:
|
|
44 |
u.upload(fn=before_processing, inputs=None, outputs=[u, d]).then(upload_file, [u, dropdown1, dropdown2], [u, d])
|
45 |
d.click(download_file, None, [u, d])
|
46 |
if __name__ == "__main__":
|
47 |
-
demo.launch()
|
|
|
33 |
gr.Interface(fn=translator.translate, inputs=["text", "text", "text"], outputs="text")
|
34 |
with gr.Tab("Documents"):
|
35 |
with gr.Row():
|
36 |
+
dropdown1 = gr.Dropdown(label="Source language", choices=["en", "ca"], value=None, interactive=True)
|
|
|
37 |
dropdown2 = gr.Dropdown(label="Target language", choices=["en", "ca"], value=None, interactive=True)
|
38 |
gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
|
39 |
with gr.Row():
|
|
|
43 |
u.upload(fn=before_processing, inputs=None, outputs=[u, d]).then(upload_file, [u, dropdown1, dropdown2], [u, d])
|
44 |
d.click(download_file, None, [u, d])
|
45 |
if __name__ == "__main__":
|
46 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
readme.md
CHANGED
@@ -24,4 +24,9 @@ need to use fastalign on that side since the current project already runs it.
|
|
24 |
|
25 |
### salamandrata7b_translator
|
26 |
|
27 |
-
Class that uses huggingface's demo.
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
### salamandrata7b_translator
|
26 |
|
27 |
+
Class that uses huggingface's demo.
|
28 |
+
|
29 |
+
## Docker
|
30 |
+
|
31 |
+
sudo docker build -t document-translator .
|
32 |
+
docker run -p 7860:7860 --rm -it document-translator
|
src/translate_any_doc.py
CHANGED
@@ -368,6 +368,8 @@ def translate_document(input_file: str, source_lang: str, target_lang: str,
|
|
368 |
temp_folder: str = "tmp",
|
369 |
tikal_folder: str = "okapi-apps_gtk2-linux-x86_64_1.47.0", with_format: bool = True) -> str:
|
370 |
input_filename = input_file.split("/")[-1]
|
|
|
|
|
371 |
# copy the original file to the temporal folder to avoid common issues with tikal
|
372 |
temp_input_file = os.path.join(temp_folder, input_filename)
|
373 |
shutil.copy(input_file, temp_input_file)
|
|
|
368 |
temp_folder: str = "tmp",
|
369 |
tikal_folder: str = "okapi-apps_gtk2-linux-x86_64_1.47.0", with_format: bool = True) -> str:
|
370 |
input_filename = input_file.split("/")[-1]
|
371 |
+
os.makedirs(temp_folder, exist_ok=True)
|
372 |
+
|
373 |
# copy the original file to the temporal folder to avoid common issues with tikal
|
374 |
temp_input_file = os.path.join(temp_folder, input_filename)
|
375 |
shutil.copy(input_file, temp_input_file)
|