File size: 2,121 Bytes
08bc52f
c015fd4
 
 
197f492
 
 
c33b262
197f492
 
 
7faa9af
197f492
 
 
08bc52f
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
"""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(comman.strip()) < 100

    if is_command:
        proc = sp.Popen(
            split(command), encoding="utf8", stdout=-1, stderr=-1
        )  # sp.PIPE: -1
        try:
            # out = sp.check_output(split(command), encoding="utf8", stderr=STDOUT)
            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

    # not is_command: text, do seg_text
    _ = "\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)