rbanfield commited on
Commit
c0bca30
·
1 Parent(s): 8d68f9a
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,15 +1,21 @@
1
  from subprocess import Popen, PIPE, STDOUT, check_output
2
  import tempfile
3
  import gradio as gr
 
4
 
5
  def run(input_image):
6
  output = check_output(["chmod", "a+x", "bin/detect-image"])
7
- cmd = 'bin/detect-image ' + input_image
8
- p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
9
- return p.stdout.read()
 
 
 
 
 
10
 
11
  gr.Interface(
12
  fn=run,
13
  inputs=gr.Image(type="filepath", label="Input Image"),
14
- outputs=gr.Textbox(),
15
  ).launch()
 
1
  from subprocess import Popen, PIPE, STDOUT, check_output
2
  import tempfile
3
  import gradio as gr
4
+ from PIL import Image
5
 
6
  def run(input_image):
7
  output = check_output(["chmod", "a+x", "bin/detect-image"])
8
+
9
+ with tempfile.TemporaryDirectory() as tmpdir:
10
+ output_image_filename = tmpdir + "/result.jpg"
11
+ cmd = 'bin/detect-image ' + input_image + ' ' + output_image_filename
12
+ p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
13
+ i = Image.open(output_image_filename)
14
+
15
+ return p.stdout.read(), i
16
 
17
  gr.Interface(
18
  fn=run,
19
  inputs=gr.Image(type="filepath", label="Input Image"),
20
+ outputs=[gr.Image(type="pil"), gr.Textbox()],
21
  ).launch()