|
"""Talk to spaces VM via subprocess.check_output.""" |
|
|
|
import subprocess as sp |
|
from shlex import split |
|
|
|
|
|
from inspect import cleandoc |
|
import gradio as gr |
|
from logzero import logger |
|
|
|
from gradiobee.seg_text import seg_text |
|
|
|
|
|
|
|
def process(command): |
|
"""Probe vm.""" |
|
|
|
|
|
|
|
|
|
is_command = True |
|
is_command = command.strip().splitlines().__len__() < 2 and len(command.strip()) < 100 |
|
|
|
if is_command: |
|
try: |
|
|
|
proc = sp.Popen( |
|
split(command), encoding="utf8", stdout=-1, stderr=-1 |
|
) |
|
out, err = proc.communicate() |
|
except Exception as e: |
|
out, err = "", str(e) |
|
|
|
out = "\n".join( |
|
( |
|
out, |
|
err, |
|
) |
|
).strip() |
|
if not out: |
|
out = "No output, that's all we know." |
|
|
|
return out |
|
|
|
|
|
_ = "\n".join(seg_text(command.strip())) |
|
_ = seg_text(command.strip()) |
|
return cleandoc( |
|
f"""seg_text output (segmented sents): |
|
{_} |
|
""" |
|
).strip() |
|
|
|
|
|
iface = gr.Interface( |
|
|
|
|
|
fn=process, |
|
|
|
inputs=gr.inputs.Textbox( |
|
lines=5, |
|
placeholder="Type or paste input here then click 'Submit'", |
|
default="python -m site", |
|
label="command or multiline text", |
|
), |
|
outputs="text", |
|
examples=[ |
|
"cat /proc/version", |
|
"free # show free memory", |
|
"uname -m", |
|
"df -h .", |
|
"cat /proc/cpuinfo", |
|
"""python -c "from psutil import virtual_memory; print(virtual_memory())" """, |
|
], |
|
title="probe the system", |
|
description="Talk to the system via subprocess.check_output ", |
|
) |
|
|
|
|
|
iface.launch(debug=True) |
|
|