Update webui_with_vnc.py
Browse files- webui_with_vnc.py +62 -8
webui_with_vnc.py
CHANGED
|
@@ -1,10 +1,64 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import argparse
|
| 4 |
-
import gradio as gr
|
| 5 |
-
from src.webui.interface import theme_map, create_ui
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def main():
|
| 10 |
parser = argparse.ArgumentParser(description="Gradio WebUI for Browser Agent")
|
|
@@ -17,17 +71,17 @@ def main():
|
|
| 17 |
base_ui = create_ui(theme_name=args.theme)
|
| 18 |
|
| 19 |
# Combine into single Gradio app
|
| 20 |
-
with gr.Blocks(theme=args.theme) as demo:
|
| 21 |
gr.Markdown("# 🌐 Browser Agent Web-UI")
|
| 22 |
|
| 23 |
with gr.Tab("Main App"):
|
| 24 |
base_ui.render()
|
| 25 |
|
| 26 |
with gr.Tab("Web VNC"):
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
demo.queue().launch(server_name=args.ip, server_port=args.port)
|
| 30 |
|
| 31 |
-
|
| 32 |
if __name__ == "__main__":
|
| 33 |
-
main()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import threading
|
| 4 |
import os
|
| 5 |
import argparse
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Example theme map for the argument parser (add more themes if you have them)
|
| 8 |
+
theme_map = {
|
| 9 |
+
"Ocean": gr.themes.Ocean(),
|
| 10 |
+
"Default": gr.themes.Default(),
|
| 11 |
+
# Add other themes as needed
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
# Function to run VNC setup (generates .vnc/passwd)
|
| 15 |
+
def setup_vnc(password):
|
| 16 |
+
vnc_dir = os.path.expanduser("~/.vnc")
|
| 17 |
+
os.makedirs(vnc_dir, exist_ok=True)
|
| 18 |
+
passwd_file = os.path.join(vnc_dir, "passwd")
|
| 19 |
+
proc = subprocess.Popen(
|
| 20 |
+
f"echo '{password}' | vncpasswd -f > '{passwd_file}'",
|
| 21 |
+
shell=True,
|
| 22 |
+
stdout=subprocess.PIPE,
|
| 23 |
+
stderr=subprocess.PIPE,
|
| 24 |
+
)
|
| 25 |
+
stdout, stderr = proc.communicate()
|
| 26 |
+
os.chmod(passwd_file, 0o600)
|
| 27 |
+
return f"VNC password set to: {password}\n{stdout.decode()}\n{stderr.decode()}"
|
| 28 |
+
|
| 29 |
+
# Function to run the webui.py application
|
| 30 |
+
def start_webui(ip="0.0.0.0", port=7860):
|
| 31 |
+
# This will run in a thread
|
| 32 |
+
def run():
|
| 33 |
+
subprocess.run(["python", "webui.py", "--ip", ip, "--port", str(port)], cwd="/app")
|
| 34 |
+
thread = threading.Thread(target=run, daemon=True)
|
| 35 |
+
thread.start()
|
| 36 |
+
return f"webui.py started at http://{ip}:{port}"
|
| 37 |
+
|
| 38 |
+
# Gradio interface for VNC setup
|
| 39 |
+
def vnc_setup(password):
|
| 40 |
+
result = setup_vnc(password)
|
| 41 |
+
return result
|
| 42 |
+
|
| 43 |
+
# Main app UI (tab content)
|
| 44 |
+
def create_ui(theme_name="Ocean"):
|
| 45 |
+
with gr.Blocks(theme=theme_map.get(theme_name, gr.themes.Ocean())) as base_ui:
|
| 46 |
+
gr.Markdown("## WebUI and VNC Setup")
|
| 47 |
+
|
| 48 |
+
with gr.Tab("Start WebUI"):
|
| 49 |
+
with gr.Row():
|
| 50 |
+
ip = gr.Textbox(label="IP", value="0.0.0.0")
|
| 51 |
+
port = gr.Number(label="Port", value=7788)
|
| 52 |
+
webui_btn = gr.Button("Start WebUI")
|
| 53 |
+
webui_out = gr.Textbox(label="WebUI Output")
|
| 54 |
+
webui_btn.click(start_webui, inputs=[ip, port], outputs=webui_out)
|
| 55 |
+
|
| 56 |
+
with gr.Tab("VNC Setup"):
|
| 57 |
+
vnc_password = gr.Textbox(label="VNC Password", type="password")
|
| 58 |
+
vnc_btn = gr.Button("Setup VNC Password")
|
| 59 |
+
vnc_out = gr.Textbox(label="VNC Setup Output")
|
| 60 |
+
vnc_btn.click(vnc_setup, inputs=[vnc_password], outputs=vnc_out)
|
| 61 |
+
return base_ui
|
| 62 |
|
| 63 |
def main():
|
| 64 |
parser = argparse.ArgumentParser(description="Gradio WebUI for Browser Agent")
|
|
|
|
| 71 |
base_ui = create_ui(theme_name=args.theme)
|
| 72 |
|
| 73 |
# Combine into single Gradio app
|
| 74 |
+
with gr.Blocks(theme=theme_map[args.theme]) as demo:
|
| 75 |
gr.Markdown("# 🌐 Browser Agent Web-UI")
|
| 76 |
|
| 77 |
with gr.Tab("Main App"):
|
| 78 |
base_ui.render()
|
| 79 |
|
| 80 |
with gr.Tab("Web VNC"):
|
| 81 |
+
# The iframe must point to the actual noVNC server (default: localhost:6080/vnc.html)
|
| 82 |
+
gr.HTML('<iframe src="http://localhost:6080/vnc.html" width="100%" height="800" style="border:none;"></iframe>')
|
| 83 |
|
| 84 |
demo.queue().launch(server_name=args.ip, server_port=args.port)
|
| 85 |
|
|
|
|
| 86 |
if __name__ == "__main__":
|
| 87 |
+
main()
|