Spaces:
Runtime error
Runtime error
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() | |