File size: 701 Bytes
78709a4
eabd2bd
671307d
c0bca30
671307d
 
78709a4
c0bca30
 
 
 
 
 
 
 
671307d
 
 
eabd2bd
c0bca30
671307d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from subprocess import Popen, PIPE, STDOUT, check_output
import tempfile
import gradio as gr
from PIL import Image

def run(input_image):
    output = check_output(["chmod", "a+x", "bin/detect-image"])

    with tempfile.TemporaryDirectory() as tmpdir:
        output_image_filename = tmpdir + "/result.jpg"
        cmd = 'bin/detect-image ' + input_image + ' ' + output_image_filename
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
        i = Image.open(output_image_filename)

    return p.stdout.read(), i

gr.Interface(
    fn=run,
    inputs=gr.Image(type="filepath", label="Input Image"),
    outputs=[gr.Image(type="pil"), gr.Textbox()],
).launch()