Update Dockerfile
Browse files- Dockerfile +51 -12
Dockerfile
CHANGED
|
@@ -1,18 +1,57 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
&& apt-get install -y --no-install-recommends ffmpeg git curl bash ca-certificates \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
RUN pip install --no-cache-dir -U pip \
|
| 16 |
-
&& pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import threading
|
| 4 |
|
| 5 |
+
# منع Gradio من اعتبار localhost غير متاح بسبب إعدادات البروكسي
|
| 6 |
+
os.environ["NO_PROXY"] = "localhost,127.0.0.1,0.0.0.0"
|
| 7 |
+
os.environ["no_proxy"] = "localhost,127.0.0.1,0.0.0.0"
|
| 8 |
|
| 9 |
+
import gradio as gr
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
+
LOG_PATH = os.path.join(BASE_DIR, "bot.log")
|
| 13 |
+
os.environ["APP_DIR"] = BASE_DIR
|
| 14 |
+
# شيم يضيف typing.Self للبوت الذي يعمل كعملية منفصلة
|
| 15 |
+
os.environ["PYTHONPATH"] = os.path.join(BASE_DIR, "shim") + os.pathsep + os.environ.get("PYTHONPATH", "")
|
| 16 |
|
| 17 |
+
_bot = None
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
def _run_bot():
|
| 21 |
+
global _bot
|
| 22 |
+
with open(LOG_PATH, "a", encoding="utf-8") as log:
|
| 23 |
+
_bot = subprocess.Popen(
|
| 24 |
+
["bash", "ba.sh"],
|
| 25 |
+
cwd=BASE_DIR,
|
| 26 |
+
stdout=log,
|
| 27 |
+
stderr=subprocess.STDOUT,
|
| 28 |
+
env=os.environ.copy(),
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def bot_status():
|
| 33 |
+
if _bot is None:
|
| 34 |
+
return "البوت لم يبدأ بعد"
|
| 35 |
+
code = _bot.poll()
|
| 36 |
+
if code is None:
|
| 37 |
+
return "البوت يعمل"
|
| 38 |
+
return f"البوت توقف برمز {code}"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def bot_logs():
|
| 42 |
+
if not os.path.exists(LOG_PATH):
|
| 43 |
+
return "لا توجد سجلات بعد"
|
| 44 |
+
with open(LOG_PATH, encoding="utf-8", errors="replace") as f:
|
| 45 |
+
return f.read()[-5000:]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
threading.Thread(target=_run_bot, daemon=True).start()
|
| 49 |
+
|
| 50 |
+
with gr.Blocks() as demo:
|
| 51 |
+
gr.Markdown("# Tython Userbot")
|
| 52 |
+
status_box = gr.Textbox(label="الحالة", value=bot_status, interactive=False)
|
| 53 |
+
log_box = gr.Textbox(label="السجل", lines=20, value=bot_logs, interactive=False)
|
| 54 |
+
refresh = gr.Button("تحديث")
|
| 55 |
+
refresh.click(lambda: (bot_status(), bot_logs()), outputs=[status_box, log_box])
|
| 56 |
+
|
| 57 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|