Malek NASKI commited on
Commit
6ac8934
1 Parent(s): 39c01b0

Add application file

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ def pred(text):
5
+ model = "averaged-10-epoch.pt"
6
+ hf_repo_id = "malloc/OpenNMT-py-English-German-Transformer"
7
+ src = "src-test.txt"
8
+ with open(src, 'w') as f:
9
+ f.write(text)
10
+ output = "pred.txt"
11
+ os.system(f"onmt_translate -model {model} -hf_repo_id {hf_repo_id} -src {src} -output {output}")
12
+
13
+ with open(output) as f:
14
+ translation = f.read()
15
+ return translation
16
+
17
+
18
+ iface = gr.Interface(
19
+ fn=pred,
20
+ inputs= gr.inputs.Textbox(lines=2, placeholder="Enter English text to translate..."),
21
+ outputs=["text"],
22
+ theme="huggingface")
23
+
24
+ iface.launch()