binary1ne commited on
Commit
7739f92
·
verified ·
1 Parent(s): ba5fd54

Update webui_with_vnc.py

Browse files
Files changed (1) hide show
  1. webui_with_vnc.py +49 -49
webui_with_vnc.py CHANGED
@@ -4,61 +4,61 @@ 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")
 
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")