Spaces:
Runtime error
Runtime error
Boning c
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,11 +12,11 @@ NO_VNC_IFRAME = """
|
|
| 12 |
</iframe>
|
| 13 |
"""
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
return NO_VNC_IFRAME
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
result = subprocess.run(
|
| 22 |
cmd,
|
|
@@ -27,31 +27,31 @@ NO_VNC_IFRAME = """
|
|
| 27 |
)
|
| 28 |
return result.stdout + result.stderr
|
| 29 |
|
| 30 |
-
|
| 31 |
dest_path = os.path.join(WORKDIR, os.path.basename(file.name))
|
| 32 |
with open(dest_path, "wb") as f:
|
| 33 |
|
| 34 |
f.write(file.read())
|
| 35 |
return f"✅ Uploaded to: {dest_path}"
|
| 36 |
|
| 37 |
-
|
| 38 |
gr.Markdown("# 🖥️ Offline Visual Sandbox (no API, no cost)")
|
| 39 |
|
| 40 |
-
|
| 41 |
launch_btn = gr.Button("Launch Desktop")
|
| 42 |
desktop_view = gr.HTML()
|
| 43 |
launch_btn.click(start_desktop, outputs=desktop_view)
|
| 44 |
|
| 45 |
-
|
| 46 |
cmd_input = gr.Textbox(label="Shell Command", placeholder="Try 'ls /home/user/workspace'")
|
| 47 |
run_btn = gr.Button("Run")
|
| 48 |
cmd_output = gr.Textbox(label="Command Output", lines=10)
|
| 49 |
run_btn.click(run_shell, inputs=cmd_input, outputs=cmd_output)
|
| 50 |
|
| 51 |
-
|
| 52 |
file_input = gr.File(label="Upload File")
|
| 53 |
status_output = gr.Textbox(label="Upload Status")
|
| 54 |
file_input.change(upload_file, inputs=file_input, outputs=status_output)
|
| 55 |
|
| 56 |
-
|
| 57 |
server_name="0.0.0.0",
|
|
|
|
| 12 |
</iframe>
|
| 13 |
"""
|
| 14 |
|
| 15 |
+
def start_desktop():
|
| 16 |
|
| 17 |
return NO_VNC_IFRAME
|
| 18 |
|
| 19 |
+
def run_shell(cmd):
|
| 20 |
|
| 21 |
result = subprocess.run(
|
| 22 |
cmd,
|
|
|
|
| 27 |
)
|
| 28 |
return result.stdout + result.stderr
|
| 29 |
|
| 30 |
+
def upload_file(file):
|
| 31 |
dest_path = os.path.join(WORKDIR, os.path.basename(file.name))
|
| 32 |
with open(dest_path, "wb") as f:
|
| 33 |
|
| 34 |
f.write(file.read())
|
| 35 |
return f"✅ Uploaded to: {dest_path}"
|
| 36 |
|
| 37 |
+
with gr.Blocks(css="@import url('https://cdn.simplecss.org/simple.min.css');") as demo:
|
| 38 |
gr.Markdown("# 🖥️ Offline Visual Sandbox (no API, no cost)")
|
| 39 |
|
| 40 |
+
with gr.Tab("Desktop"):
|
| 41 |
launch_btn = gr.Button("Launch Desktop")
|
| 42 |
desktop_view = gr.HTML()
|
| 43 |
launch_btn.click(start_desktop, outputs=desktop_view)
|
| 44 |
|
| 45 |
+
with gr.Tab("Shell"):
|
| 46 |
cmd_input = gr.Textbox(label="Shell Command", placeholder="Try 'ls /home/user/workspace'")
|
| 47 |
run_btn = gr.Button("Run")
|
| 48 |
cmd_output = gr.Textbox(label="Command Output", lines=10)
|
| 49 |
run_btn.click(run_shell, inputs=cmd_input, outputs=cmd_output)
|
| 50 |
|
| 51 |
+
with gr.Tab("Upload"):
|
| 52 |
file_input = gr.File(label="Upload File")
|
| 53 |
status_output = gr.Textbox(label="Upload Status")
|
| 54 |
file_input.change(upload_file, inputs=file_input, outputs=status_output)
|
| 55 |
|
| 56 |
+
demo.launch(
|
| 57 |
server_name="0.0.0.0",
|