Spaces:
Sleeping
Sleeping
File size: 2,115 Bytes
0bee3d6 0ca4a58 4fef6ae dd52df4 f032f5d 9ebfeae dd52df4 9ebfeae b8619bc 4fef6ae 0ca4a58 9ebfeae f032f5d b8619bc f032f5d b8619bc 9ebfeae 02dde9f 9ebfeae dd52df4 0ca4a58 9ebfeae f032f5d 9ebfeae 02dde9f 9ebfeae 02dde9f b8619bc 9ebfeae b8619bc 0ca4a58 9ebfeae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import streamlit as st
import subprocess
import os
import signal
# Track process for running 'Powers'
process = None
st.title("Powers Bot Control Panel ⚡")
st.write("Use this panel to start/stop the bot and view real-time logs.")
# Container to display logs dynamically
log_container = st.empty()
if st.button("Start Powers"):
if process is None or process.poll() is not None:
# Step 1: Install dependencies
with st.spinner("Installing dependencies... This might take a while."):
install_process = subprocess.run(["pip3", "install", "-U", "-r", "requirements.txt"], text=True, capture_output=True)
if install_process.returncode == 0:
st.success("Dependencies installed successfully!")
else:
st.error("Error installing dependencies:")
st.error(install_process.stderr)
st.stop() # Stop here if installation fails
# Step 2: Launch the bot and stream logs
process = subprocess.Popen(["python3", "-m", "Powers"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid, text=True)
st.success("`Powers` bot started successfully!")
else:
st.warning("`Powers` bot is already running!")
if st.button("Stop Powers"):
if process is not None:
os.killpg(os.getpgid(process.pid), signal.SIGTERM) # Stop the entire process group
process = None
st.success("`Powers` bot stopped!")
else:
st.warning("No running bot process to stop.")
# Check if the process is running and show logs dynamically
if process and process.poll() is None:
st.write("`Powers` bot is **running**! 🚀")
# Display logs in real-time
with log_container:
st.text("Real-time Logs:")
while True:
output = process.stdout.readline()
if output == "" and process.poll() is not None:
break # Stop loop when process ends
if output:
st.write(output.strip()) # Display log line by line in the UI
else:
st.write("`Powers` bot is **not running**.")
|