xdragxt commited on
Commit
b8619bc
·
verified ·
1 Parent(s): f032f5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -7,21 +7,25 @@ import signal
7
  process = None
8
 
9
  st.title("Powers Bot Control Panel ⚡")
10
- st.write("This control panel lets you install dependencies and start/stop the Powers bot.")
 
 
 
11
 
12
  if st.button("Start Powers"):
13
  if process is None or process.poll() is not None:
14
  # Step 1: Install dependencies
15
  with st.spinner("Installing dependencies... This might take a while."):
16
- install_process = subprocess.run(["pip3", "install", "-U", "-r", "requirements.txt"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
17
  if install_process.returncode == 0:
18
  st.success("Dependencies installed successfully!")
19
  else:
20
  st.error("Error installing dependencies:")
21
  st.error(install_process.stderr)
22
-
23
- # Step 2: Launch the Powers bot after installing dependencies
24
- process = subprocess.Popen(["python3", "-m", "powers"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)
 
25
  st.success("`Powers` bot started successfully!")
26
  else:
27
  st.warning("`Powers` bot is already running!")
@@ -34,7 +38,18 @@ if st.button("Stop Powers"):
34
  else:
35
  st.warning("No running bot process to stop.")
36
 
 
37
  if process and process.poll() is None:
38
  st.write("`Powers` bot is **running**! 🚀")
 
 
 
 
 
 
 
 
 
 
39
  else:
40
  st.write("`Powers` bot is **not running**.")
 
7
  process = None
8
 
9
  st.title("Powers Bot Control Panel ⚡")
10
+ st.write("Use this panel to start/stop the bot and view real-time logs.")
11
+
12
+ # Container to display logs dynamically
13
+ log_container = st.empty()
14
 
15
  if st.button("Start Powers"):
16
  if process is None or process.poll() is not None:
17
  # Step 1: Install dependencies
18
  with st.spinner("Installing dependencies... This might take a while."):
19
+ install_process = subprocess.run(["pip3", "install", "-U", "-r", "requirements.txt"], text=True, capture_output=True)
20
  if install_process.returncode == 0:
21
  st.success("Dependencies installed successfully!")
22
  else:
23
  st.error("Error installing dependencies:")
24
  st.error(install_process.stderr)
25
+ st.stop() # Stop here if installation fails
26
+
27
+ # Step 2: Launch the bot and stream logs
28
+ process = subprocess.Popen(["python3", "-m", "Powers"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid, text=True)
29
  st.success("`Powers` bot started successfully!")
30
  else:
31
  st.warning("`Powers` bot is already running!")
 
38
  else:
39
  st.warning("No running bot process to stop.")
40
 
41
+ # Check if the process is running and show logs dynamically
42
  if process and process.poll() is None:
43
  st.write("`Powers` bot is **running**! 🚀")
44
+
45
+ # Display logs in real-time
46
+ with log_container:
47
+ st.text("Real-time Logs:")
48
+ while True:
49
+ output = process.stdout.readline()
50
+ if output == "" and process.poll() is not None:
51
+ break # Stop loop when process ends
52
+ if output:
53
+ st.write(output.strip()) # Display log line by line in the UI
54
  else:
55
  st.write("`Powers` bot is **not running**.")