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