Download app.py from test978/Cloud_VPS: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/spaces/test978/Cloud_VPS/resolve/main/app.py
- Command line
-
hf download hf://spaces/test978/Cloud_VPS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/test978/Cloud_VPS/resolve/main/app.py
3.61 kB
| import gradio as gr | |
| import subprocess | |
| import os | |
| import hashlib | |
| import threading | |
| import time | |
| # ================= CONFIG ================= | |
| USERNAME = "wolf" | |
| PASSWORD = "wolf123" | |
| WORKSPACE = os.getcwd() | |
| BOT_DIR = os.path.join(WORKSPACE, "bots") | |
| LOG_DIR = os.path.join(WORKSPACE, "logs") | |
| os.makedirs(BOT_DIR, exist_ok=True) | |
| os.makedirs(LOG_DIR, exist_ok=True) | |
| processes = {} | |
| # ================= AUTH ================= | |
| def login(u, p): | |
| if u == USERNAME and p == PASSWORD: | |
| return True, "โ ุชู ุงูุฏุฎูู" | |
| return False, "โ ุฎุทุฃ" | |
| # ================= SAVE ================= | |
| def save_bot(name, code): | |
| path = os.path.join(BOT_DIR, name) | |
| with open(path, "w") as f: | |
| f.write(code) | |
| return "โ ุชู ุงูุญูุธ" | |
| # ================= RUN ================= | |
| def run_bot(name): | |
| path = os.path.join(BOT_DIR, name) | |
| if not os.path.exists(path): | |
| return "โ ุงูู ูู ุบูุฑ ู ูุฌูุฏ" | |
| if name in processes and processes[name].poll() is None: | |
| return "โ ๏ธ ุงูุจูุช ูุนู ู" | |
| log_file = open(os.path.join(LOG_DIR, f"{name}.log"), "w") | |
| proc = subprocess.Popen( | |
| ["python3", path], | |
| cwd=BOT_DIR, | |
| stdout=log_file, | |
| stderr=log_file | |
| ) | |
| processes[name] = proc | |
| return f"๐ ุชู ุงูุชุดุบูู PID: {proc.pid}" | |
| # ================= STOP ================= | |
| def stop_bot(name): | |
| if name not in processes: | |
| return "โ ูุง ููุฌุฏ" | |
| proc = processes[name] | |
| if proc.poll() is None: | |
| proc.terminate() | |
| return "๐ ุชู ุงูุฅููุงู" | |
| return "โ ๏ธ ู ุชููู" | |
| # ================= STATUS ================= | |
| def status_bot(name): | |
| if name not in processes: | |
| return "๐ญ ูุง ููุฌุฏ" | |
| if processes[name].poll() is None: | |
| return "๐ข ูุนู ู" | |
| return "๐ด ู ุชููู" | |
| # ================= LOG ================= | |
| def read_log(name): | |
| path = os.path.join(LOG_DIR, f"{name}.log") | |
| if not os.path.exists(path): | |
| return "๐ญ ูุง ููุฌุฏ ููู" | |
| with open(path, "r") as f: | |
| return f.read()[-4000:] | |
| # ================= AUTO RESTART ================= | |
| def monitor(): | |
| while True: | |
| for name, proc in list(processes.items()): | |
| if proc.poll() is not None: | |
| run_bot(name) | |
| time.sleep(5) | |
| threading.Thread(target=monitor, daemon=True).start() | |
| # ================= UI ================= | |
| with gr.Blocks(title="Wolf VPS") as app: | |
| login_state = gr.State(False) | |
| with gr.Column(visible=True) as login_page: | |
| gr.Markdown("## ๐ ุฏุฎูู") | |
| u = gr.Textbox() | |
| p = gr.Textbox(type="password") | |
| btn = gr.Button("Login") | |
| msg = gr.Textbox() | |
| with gr.Column(visible=False) as panel: | |
| gr.Markdown("## ๐บ Wolf Bot Panel") | |
| name = gr.Textbox(value="bot.py") | |
| code = gr.Code(language="python") | |
| with gr.Row(): | |
| save = gr.Button("๐พ") | |
| run = gr.Button("โถ๏ธ") | |
| stop = gr.Button("๐") | |
| stat = gr.Button("๐") | |
| out = gr.Textbox() | |
| logs = gr.Textbox(lines=15) | |
| refresh = gr.Button("๐ Logs") | |
| def do_login(x, y): | |
| ok, m = login(x, y) | |
| if ok: | |
| return m, False, True | |
| return m, True, False | |
| btn.click(do_login, [u, p], [msg, login_page, panel]) | |
| save.click(save_bot, [name, code], [out]) | |
| run.click(run_bot, [name], [out]) | |
| stop.click(stop_bot, [name], [out]) | |
| stat.click(status_bot, [name], [out]) | |
| refresh.click(read_log, [name], [logs]) | |
| app.launch(server_name="0.0.0.0", server_port=7860) |