Agung1453 commited on
Commit
410d95d
·
verified ·
1 Parent(s): e2a6dbd

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -25,19 +25,26 @@ def extract_host_port(url):
25
  def start_vnc(index):
26
  global desktops, vnc_urls, vnc_host_ports
27
  if desktops[index] is None:
28
- desktops[index] = Sandbox.create(
29
- template=None,
30
- resolution=(1024, 768),
31
- dpi=96,
32
- allow_internet_access=True
33
- )
34
- desktops[index].stream.start(require_auth=False)
35
- vnc_urls[index] = desktops[index].stream.get_url()
36
- vnc_host_ports[index] = extract_host_port(vnc_urls[index])
37
- return (
38
- f"<iframe src='{vnc_urls[index]}' width='100%' height='300px' style='border:none;'></iframe>",
39
- f"✅ VNC {index+1} Started — Use RealVNC: {vnc_host_ports[index]}"
40
- )
 
 
 
 
 
 
 
41
  else:
42
  return (
43
  f"<iframe src='{vnc_urls[index]}' width='100%' height='300px' style='border:none;'></iframe>",
@@ -47,7 +54,10 @@ def start_vnc(index):
47
  def stop_vnc(index):
48
  global desktops, vnc_urls, vnc_host_ports
49
  if desktops[index]:
50
- desktops[index].kill()
 
 
 
51
  desktops[index] = None
52
  vnc_urls[index] = None
53
  vnc_host_ports[index] = None
@@ -77,8 +87,6 @@ with gr.Blocks() as demo:
77
 
78
  iframe_displays = []
79
  status_displays = []
80
- start_buttons = []
81
- stop_buttons = []
82
 
83
  for i in range(5):
84
  gr.HTML(f"<h3 style='text-align:center'>VNC {i+1}</h3>")
@@ -92,8 +100,6 @@ with gr.Blocks() as demo:
92
 
93
  iframe_displays.append(iframe)
94
  status_displays.append(status)
95
- start_buttons.append(start_btn)
96
- stop_buttons.append(stop_btn)
97
 
98
  gr.HTML("<h3 style='text-align:center'>Kirim Teks ke Semua VNC</h3>")
99
  teks_input = gr.Textbox(placeholder="Ketik teks untuk VNC", label="VNC Keyboard")
 
25
  def start_vnc(index):
26
  global desktops, vnc_urls, vnc_host_ports
27
  if desktops[index] is None:
28
+ try:
29
+ desktops[index] = Sandbox.create(
30
+ template=None,
31
+ resolution=(1024, 768),
32
+ dpi=96,
33
+ allow_internet_access=True,
34
+ api_key=E2B_KEYS[index]
35
+ )
36
+ desktops[index].stream.start(require_auth=False)
37
+ vnc_urls[index] = desktops[index].stream.get_url()
38
+ vnc_host_ports[index] = extract_host_port(vnc_urls[index])
39
+ return (
40
+ f"<iframe src='{vnc_urls[index]}' width='100%' height='300px' style='border:none;'></iframe>",
41
+ f"✅ VNC {index+1} Started — Use RealVNC: {vnc_host_ports[index]}"
42
+ )
43
+ except Exception as ex:
44
+ return (
45
+ "<p style='color:red;'>❌ Gagal memulai VNC</p>",
46
+ f"Error: {ex}"
47
+ )
48
  else:
49
  return (
50
  f"<iframe src='{vnc_urls[index]}' width='100%' height='300px' style='border:none;'></iframe>",
 
54
  def stop_vnc(index):
55
  global desktops, vnc_urls, vnc_host_ports
56
  if desktops[index]:
57
+ try:
58
+ desktops[index].kill()
59
+ except Exception:
60
+ pass
61
  desktops[index] = None
62
  vnc_urls[index] = None
63
  vnc_host_ports[index] = None
 
87
 
88
  iframe_displays = []
89
  status_displays = []
 
 
90
 
91
  for i in range(5):
92
  gr.HTML(f"<h3 style='text-align:center'>VNC {i+1}</h3>")
 
100
 
101
  iframe_displays.append(iframe)
102
  status_displays.append(status)
 
 
103
 
104
  gr.HTML("<h3 style='text-align:center'>Kirim Teks ke Semua VNC</h3>")
105
  teks_input = gr.Textbox(placeholder="Ketik teks untuk VNC", label="VNC Keyboard")