generator_fn / app.py
pngwn's picture
pngwn HF Staff
Update app.py
a03b8e5 verified
raw
history blame contribute delete
675 Bytes
import gradio as gr
import subprocess
def fn(txt):
v = ""
command = ["python", "-u", "script.py"]
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
if process.stdout is None:
raise ValueError("stdout is None")
for line in process.stdout:
v += line
yield v
process.stdout.close()
return_code = process.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, command)
with gr.Blocks() as demo:
txt = gr.Code(show_label=False)
demo.load(fn, inputs=txt, outputs=txt)
demo.launch()