| import gradio as gr |
| import subprocess |
| import os |
| import signal |
|
|
| bot_process = None |
|
|
| def start_bot(): |
| global bot_process |
| if bot_process and bot_process.poll() is None: |
| return "β
Bot sudah berjalan" |
| |
| bot_process = subprocess.Popen( |
| ["node", "bot.js"], |
| stdout=subprocess.PIPE, |
| stderr=subprocess.STDOUT, |
| text=True, |
| cwd=os.path.dirname(os.path.abspath(__file__)), |
| preexec_fn=os.setsid if hasattr(os, 'setsid') else None |
| ) |
| return "π Bot started" |
|
|
| def stop_bot(): |
| global bot_process |
| if bot_process and bot_process.poll() is None: |
| os.killpg(os.getpgid(bot_process.pid), signal.SIGTERM) |
| bot_process = None |
| return "βΉοΈ Bot stopped" |
| return "Bot tidak aktif" |
|
|
| def get_log(): |
| global bot_process |
| if bot_process and bot_process.poll() is None: |
| try: |
| output = bot_process.stdout.read() |
| return output[-2000:] if output else "β³ Menunggu log..." |
| except: |
| return "Error baca log" |
| return "Bot tidak aktif." |
|
|
| with gr.Blocks(css="#log {height: 400px;}") as demo: |
| gr.Markdown("# π€ Multi-Coin Faucet Bot (Tampermonkey Pattern)") |
| with gr.Row(): |
| start_btn = gr.Button("π Start", variant="primary") |
| stop_btn = gr.Button("π Stop", variant="stop") |
| log_box = gr.Textbox(label="Log", lines=20, elem_id="log") |
| refresh_btn = gr.Button("π Refresh") |
| |
| start_btn.click(fn=start_bot, outputs=gr.State()) |
| stop_btn.click(fn=stop_bot, outputs=gr.State()) |
| refresh_btn.click(fn=get_log, outputs=log_box) |
| demo.load(fn=get_log, outputs=log_box, every=3) |
|
|
| demo.launch(server_name="0.0.0.0", server_port=7860) |