File size: 2,217 Bytes
08bc52f c015fd4 197f492 c33b262 197f492 7faa9af 197f492 08bc52f 197f492 676bda1 197f492 d562426 197f492 05d53db 197f492 05d53db 197f492 05d53db 197f492 05d53db d686cc9 197f492 7faa9af c33b262 7faa9af 197f492 7faa9af 80c38e5 c90742c 80c38e5 c90742c 78ab3ee 80c38e5 7faa9af 8189ef8 7faa9af 0bf7d6b 0c951fa 0bf7d6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
"""Talk to spaces VM via subprocess.check_output."""
# import httpx
import subprocess as sp
from shlex import split
# from textwrap import dedent
from inspect import cleandoc
import gradio as gr
from logzero import logger
from gradiobee.seg_text import seg_text
# def greet(command):
def process(command):
"""Probe vm."""
# single line: command
# logger.info("input:\n\t %s", command)
# print("print input:\n\t %s" % command)
# print("print input*:\n\t %s" % "*".join(command.splitlines()))
is_command = True
is_command = command.strip().splitlines().__len__() < 2 and len(command.strip()) < 100
if is_command:
try:
# out = sp.check_output(split(command), encoding="utf8", stderr=STDOUT)
proc = sp.Popen(
split(command), encoding="utf8", stdout=-1, stderr=-1
) # sp.PIPE: -1
out, err = proc.communicate()
sucess = True
except Exception as e:
out, err = "", str(e)
sucess = False
if sucess:
out = "\n".join(
(
out,
err,
)
).strip()
if not out:
out = "No output, that's all we know."
return out
# not is_command or not flag: text, do seg_text
_ = "\n\n".join(seg_text(command.strip()))
# _ = seg_text(command.strip())
return cleandoc(
f"""seg_text output (segmented sents):
{_}
"""
).strip()
iface = gr.Interface(
# fn=greet,
# inputs="text",
fn=process,
# inputs="text",
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(share=True, debug=True)
iface.launch(debug=True)
|