Spaces:
Running
Running
import gradio as gr | |
import subprocess | |
import threading | |
logs = "" | |
def run_bot(): | |
global logs | |
process = subprocess.Popen( | |
["python3", "bot.py"], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, | |
text=True, | |
bufsize=1 | |
) | |
for line in process.stdout: | |
logs += line | |
# Start the bot in a background thread | |
threading.Thread(target=run_bot, daemon=True).start() | |
def launch_bot(): | |
return "β Bot launched successfully." | |
def get_logs(): | |
return logs[-2000:] | |
with gr.Blocks() as demo: | |
gr.Markdown("# π¬ TheMovieProviderBot Interface") | |
gr.Markdown("Interact with the bot on Telegram.") | |
gr.Markdown("[π¦ Click here to download bot files](static/setup.zip)") | |
with gr.Row(): | |
launch_btn = gr.Button("π Start Bot") | |
refresh_btn = gr.Button("π Refresh Logs") | |
log_output = gr.Textbox(label="π Bot Logs", lines=20) | |
launch_btn.click(fn=launch_bot, outputs=None) | |
refresh_btn.click(fn=get_logs, outputs=log_output) | |
demo.launch() |