Spaces:
Runtime error
Runtime error
Deploy Bot commited on
Commit Β·
6948eae
1
Parent(s): c4cbaf0
Remove Dockerfile, fix app.py for Gradio SDK
Browse files- Dockerfile +0 -19
- app.py +19 -41
Dockerfile
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
FROM python:3.12-slim
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
COPY requirements.txt .
|
| 6 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
-
|
| 8 |
-
COPY . .
|
| 9 |
-
|
| 10 |
-
# Create directory for SQLite db
|
| 11 |
-
RUN mkdir -p /data
|
| 12 |
-
|
| 13 |
-
# Set logging to stdout for container logs
|
| 14 |
-
ENV PYTHONUNBUFFERED=1
|
| 15 |
-
|
| 16 |
-
# HuggingFace Spaces requires port 7860
|
| 17 |
-
EXPOSE 7860
|
| 18 |
-
|
| 19 |
-
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,58 +1,42 @@
|
|
| 1 |
"""
|
| 2 |
MTXtyle Bot - Hugging Face Spaces Entry Point (Gradio SDK)
|
| 3 |
Runs the Telegram bot in a background thread and provides
|
| 4 |
-
a Gradio status interface
|
| 5 |
"""
|
| 6 |
import threading
|
| 7 |
-
import subprocess
|
| 8 |
-
import sys
|
| 9 |
import os
|
| 10 |
import time
|
| 11 |
import gradio as gr
|
| 12 |
|
| 13 |
bot_status = "β³ Ishga tushirilmoqda..."
|
| 14 |
-
bot_log = []
|
| 15 |
|
| 16 |
def run_bot():
|
| 17 |
-
global bot_status
|
| 18 |
|
| 19 |
token = os.getenv("BOT_TOKEN")
|
| 20 |
if not token:
|
| 21 |
bot_status = "β BOT_TOKEN topilmadi! Settings -> Secrets ga qo'shing."
|
| 22 |
-
bot_log.append("ERROR: BOT_TOKEN environment variable is not set!")
|
| 23 |
return
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
bot_status =
|
| 28 |
-
bot_log.append(f"[Attempt {attempt}] Starting bot...")
|
| 29 |
-
|
| 30 |
time.sleep(3)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
bot_log.append(f"Attempt {attempt} failed: {error_msg}")
|
| 44 |
-
bot_status = f"β οΈ Xato (urinish {attempt}), qayta urinilmoqda..."
|
| 45 |
-
time.sleep(5 * attempt)
|
| 46 |
-
else:
|
| 47 |
-
bot_status = "β Bot ishga tushmadi. Loglarni tekshiring."
|
| 48 |
|
| 49 |
def get_status():
|
| 50 |
-
|
| 51 |
-
return bot_status, log_text
|
| 52 |
-
|
| 53 |
-
def check_status(dummy=None):
|
| 54 |
-
status, logs = get_status()
|
| 55 |
-
return status, logs
|
| 56 |
|
| 57 |
# Start bot in background
|
| 58 |
bot_thread = threading.Thread(target=run_bot, daemon=True)
|
|
@@ -63,15 +47,9 @@ with gr.Blocks(title="MTXtyle Bot") as demo:
|
|
| 63 |
gr.Markdown("# π€ MTXtyle Telegram Bot")
|
| 64 |
gr.Markdown("Kiyim va aksessuarlar do'koni uchun Telegram bot")
|
| 65 |
|
| 66 |
-
|
| 67 |
-
status_box = gr.Textbox(label="Bot Holati", value=bot_status, interactive=False)
|
| 68 |
-
|
| 69 |
-
with gr.Row():
|
| 70 |
-
log_box = gr.Textbox(label="Loglar", value="", lines=10, interactive=False)
|
| 71 |
-
|
| 72 |
refresh_btn = gr.Button("π Yangilash")
|
| 73 |
-
refresh_btn.click(fn=
|
| 74 |
-
|
| 75 |
-
demo.load(fn=check_status, outputs=[status_box, log_box])
|
| 76 |
|
| 77 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
"""
|
| 2 |
MTXtyle Bot - Hugging Face Spaces Entry Point (Gradio SDK)
|
| 3 |
Runs the Telegram bot in a background thread and provides
|
| 4 |
+
a Gradio status interface.
|
| 5 |
"""
|
| 6 |
import threading
|
|
|
|
|
|
|
| 7 |
import os
|
| 8 |
import time
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
bot_status = "β³ Ishga tushirilmoqda..."
|
|
|
|
| 12 |
|
| 13 |
def run_bot():
|
| 14 |
+
global bot_status
|
| 15 |
|
| 16 |
token = os.getenv("BOT_TOKEN")
|
| 17 |
if not token:
|
| 18 |
bot_status = "β BOT_TOKEN topilmadi! Settings -> Secrets ga qo'shing."
|
|
|
|
| 19 |
return
|
| 20 |
|
| 21 |
+
# Import and run bot directly in thread
|
| 22 |
+
try:
|
| 23 |
+
bot_status = "π Bot yuklanmoqda..."
|
|
|
|
|
|
|
| 24 |
time.sleep(3)
|
| 25 |
|
| 26 |
+
# Import bot module
|
| 27 |
+
import asyncio
|
| 28 |
+
from bot import main as bot_main
|
| 29 |
+
|
| 30 |
+
bot_status = "β
Bot ishlayapti!"
|
| 31 |
|
| 32 |
+
# Run the bot
|
| 33 |
+
bot_main()
|
| 34 |
+
|
| 35 |
+
except Exception as e:
|
| 36 |
+
bot_status = f"β Xato: {str(e)[:200]}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def get_status():
|
| 39 |
+
return bot_status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Start bot in background
|
| 42 |
bot_thread = threading.Thread(target=run_bot, daemon=True)
|
|
|
|
| 47 |
gr.Markdown("# π€ MTXtyle Telegram Bot")
|
| 48 |
gr.Markdown("Kiyim va aksessuarlar do'koni uchun Telegram bot")
|
| 49 |
|
| 50 |
+
status_box = gr.Textbox(label="Bot Holati", value=bot_status, interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
refresh_btn = gr.Button("π Yangilash")
|
| 52 |
+
refresh_btn.click(fn=get_status, outputs=[status_box])
|
| 53 |
+
demo.load(fn=get_status, outputs=[status_box])
|
|
|
|
| 54 |
|
| 55 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|