File size: 549 Bytes
8f90c2f
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gradio as gr, pathlib, tempfile
from translate_xlf import translate_xlf

def translate(file, target):
    tmp_in = tempfile.NamedTemporaryFile(delete=False, suffix=".xlf")
    tmp_in.write(file.read()); tmp_in.flush()
    out = pathlib.Path(tmp_in.name).with_stem(f"{tmp_in.name}_{target}")
    translate_xlf(tmp_in.name, target, out)
    return out

demo = gr.Interface(fn=translate,
                    inputs=[gr.File(label="Fichier XLF"), gr.Textbox(label="Langue cible", value="fr")],
                    outputs=gr.File())
demo.launch()