JJFrancisco commited on
Commit
2eb99f4
1 Parent(s): af19d57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,10 +1,16 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- onmt_translate -src name -model NOS-MT-en-gl.pt --output ./output_file.txt
5
- return ./output_file.txt
6
 
7
- demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
 
 
 
 
 
 
 
 
8
 
9
  if __name__ == "__main__":
10
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ import subprocess
 
 
4
 
5
+ def translate(input_text):
6
+ command = f"onmt_translate -src {input_text} -model NOS-MT-en-gl.pt --output ./output_file.txt --replace_unk -gpu 0"
7
+ process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
8
+ stdout, stderr = process.communicate()
9
+ if process.returncode != 0:
10
+ raise Exception(f"Error occurred: {stderr.decode().strip()}")
11
+ return stdout.decode().strip()
12
+
13
+ demo = gr.Interface(fn=translate, inputs="textbox", outputs="textbox")
14
 
15
  if __name__ == "__main__":
16
  demo.launch()