Aqso commited on
Commit
6860273
·
verified ·
1 Parent(s): bfd563a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +55 -7
Dockerfile CHANGED
@@ -1,10 +1,58 @@
1
- FROM node:18
 
 
2
 
3
- # Install Wetty
4
- RUN npm install -g wetty
5
 
6
- # Expose port
7
- EXPOSE 7860
 
 
 
8
 
9
- # Start Wetty
10
- CMD ["wetty", "--base", "/", "--port", "7860", "--command", "bash"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
 
5
+ # Default working directory
6
+ current_dir = "/tmp" # Temp folder yang bisa ditulis
7
 
8
+ def run_command(cmd):
9
+ global current_dir
10
+ try:
11
+ # Split command buat cek kalau ada "cd"
12
+ parts = cmd.strip().split("&&")
13
 
14
+ for part in parts:
15
+ part = part.strip()
16
+ if part.startswith("cd "):
17
+ # Handle cd command
18
+ path = part[3:].strip()
19
+ if path == "~":
20
+ current_dir = os.path.expanduser("~")
21
+ elif path.startswith("/"):
22
+ current_dir = path
23
+ else:
24
+ current_dir = os.path.abspath(os.path.join(current_dir, path))
25
+ else:
26
+ # Jalankan command lain
27
+ result = subprocess.run(
28
+ part,
29
+ shell=True,
30
+ capture_output=True,
31
+ text=True,
32
+ cwd=current_dir,
33
+ timeout=300 # timeout 5 menit
34
+ )
35
+ output = result.stdout + "\n" + result.stderr
36
+
37
+ if result.returncode != 0:
38
+ return f"❌ Gagal di command: `{part}`\n\n{output}"
39
+
40
+ return f"✅ Berhasil!\n\n{output}"
41
+
42
+ except subprocess.TimeoutExpired:
43
+ return "⏰ Timeout, command terlalu lama!"
44
+ except Exception as e:
45
+ return f"⚠️ Error: {str(e)}"
46
+
47
+ # Interface Gradio
48
+ with gr.Blocks() as demo:
49
+ gr.Markdown("## **Terminal Web (V2)** \nJalanin perintah bash langsung di server!")
50
+ with gr.Row():
51
+ cmd_input = gr.Textbox(label="Command", placeholder="Contoh: git clone https://github.com/user/botwa.git", scale=7)
52
+ submit_btn = gr.Button("Jalankan", scale=1)
53
+ output = gr.Textbox(label="Output", lines=20)
54
+
55
+ submit_btn.click(run_command, inputs=cmd_input, outputs=output)
56
+ cmd_input.submit(run_command, inputs=cmd_input, outputs=output)
57
+
58
+ demo.launch()