Spaces:
Runtime error
Runtime error
File size: 770 Bytes
78709a4 eabd2bd 9372a3c 671307d c0bca30 671307d 78709a4 c0bca30 9372a3c 7abad1c c0bca30 cad7e16 671307d eabd2bd 9372a3c 671307d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from subprocess import Popen, PIPE, STDOUT, check_output
import tempfile
import json
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)
j = json.loads(p.stdout.read().decode("utf-8"))
#print(j)
i = Image.open(output_image_filename)
return i, j
gr.Interface(
fn=run,
inputs=gr.Image(type="filepath", label="Input Image"),
outputs=[gr.Image(type="pil"), gr.Json()],
).launch()
|