|
"""Talk to spaces VM via subprocess.check_output.""" |
|
|
|
import subprocess as sp |
|
from shlex import split |
|
import gradio as gr |
|
from gradio.seg_text import seg_text |
|
|
|
def greet(command): |
|
"""Probe vm.""" |
|
try: |
|
out = sp.check_output(split(command), encoding="utf8") |
|
except Exception as e: |
|
out = str(e) |
|
|
|
if not (out and out.strip()): |
|
out = "No output, that's all we know." |
|
return out |
|
|
|
|
|
iface = gr.Interface( |
|
fn=greet, |
|
inputs="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) |
|
|