Download Dockerfile from suphe/tython: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/suphe/tython/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/suphe/tython/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/suphe/tython/resolve/main/Dockerfile
1.8 kB
| import os | |
| import subprocess | |
| import threading | |
| # منع Gradio من اعتبار localhost غير متاح بسبب إعدادات البروكسي | |
| os.environ["NO_PROXY"] = "localhost,127.0.0.1,0.0.0.0" | |
| os.environ["no_proxy"] = "localhost,127.0.0.1,0.0.0.0" | |
| import gradio as gr | |
| BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| LOG_PATH = os.path.join(BASE_DIR, "bot.log") | |
| os.environ["APP_DIR"] = BASE_DIR | |
| # شيم يضيف typing.Self للبوت الذي يعمل كعملية منفصلة | |
| os.environ["PYTHONPATH"] = os.path.join(BASE_DIR, "shim") + os.pathsep + os.environ.get("PYTHONPATH", "") | |
| _bot = None | |
| def _run_bot(): | |
| global _bot | |
| with open(LOG_PATH, "a", encoding="utf-8") as log: | |
| _bot = subprocess.Popen( | |
| ["bash", "ba.sh"], | |
| cwd=BASE_DIR, | |
| stdout=log, | |
| stderr=subprocess.STDOUT, | |
| env=os.environ.copy(), | |
| ) | |
| def bot_status(): | |
| if _bot is None: | |
| return "البوت لم يبدأ بعد" | |
| code = _bot.poll() | |
| if code is None: | |
| return "البوت يعمل" | |
| return f"البوت توقف برمز {code}" | |
| def bot_logs(): | |
| if not os.path.exists(LOG_PATH): | |
| return "لا توجد سجلات بعد" | |
| with open(LOG_PATH, encoding="utf-8", errors="replace") as f: | |
| return f.read()[-5000:] | |
| threading.Thread(target=_run_bot, daemon=True).start() | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Tython Userbot") | |
| status_box = gr.Textbox(label="الحالة", value=bot_status, interactive=False) | |
| log_box = gr.Textbox(label="السجل", lines=20, value=bot_logs, interactive=False) | |
| refresh = gr.Button("تحديث") | |
| refresh.click(lambda: (bot_status(), bot_logs()), outputs=[status_box, log_box]) | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |