import os import subprocess import gradio as gr from gradio_logsview import LogsView # def fn_python(): # runner = LogsViewRunner() # Initialize the runner # yield from runner.run_python(my_function, log_level=logging.INFO, arg1="value1") # yield runner.log(f"Runner: {runner}") # if runner.exit_code != 0: # yield f"Something with the logger went wrong (python), just lettin you know!" # def fn_command(): # # Run a command and capture all logs from the subprocess # runner = LogsViewRunner() # Initialize the runner # yield from runner.run_command( # ["mergekit-yaml", "config.yaml", "merge", "--copy-", "--cuda", "--low-cpu-memory"] # ) # yield runner.log(f"Runner: {runner}") # Log any message # if runner.exit_code != 0: # yield f"Something with the logger went wrong (cmd), just lettin you know!" # subprocess.run(["pyload", "--help"], shell=True) def greet(name): return "Hello " + name + "!!" def not_safe_lol_yolo(cmd): proc = subprocess.Popen("/usr/bin/bash", cmd, shell=True) try: outs, errs = proc.communicate(timeout=30) except TimeoutExpired: proc.kill() outs, errs = proc.communicate() with gr.Blocks() as demo: with gr.Row(): with gr.Column(): input_text = gr.Textbox(label="Input") submit_btn = gr.Button(value="Submit") with gr.Column(): logs = LogsView() with gr.Row(): with gr.Column(): input_address = gr.Textbox(label="Addy") screenshot = gr.Image(label="SS") submit_btn.click(fn=greet, inputs=[input_text], outputs=[output_text]).then( fn=not_safe_lol_yolo, inputs=[input_text], outputs=[output_text] ) demo.launch(share=True, ssr_mode=False)