Spaces:
Runtime error
Runtime error
Deploy Bot commited on
Commit Β·
c4cbaf0
1
Parent(s): 2af8f98
Switch from Docker to Gradio SDK for network access
Browse files- README.md +3 -8
- app.py +53 -47
- requirements.txt +0 -0
README.md
CHANGED
|
@@ -3,17 +3,12 @@ title: Mtextile Bot
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
# MTXtyle - Telegram Bot
|
| 11 |
|
| 12 |
Kiyim va aksessuarlar do'koni uchun Telegram bot.
|
| 13 |
-
|
| 14 |
-
## Features
|
| 15 |
-
- Katalog va mahsulotlar boshqaruvi
|
| 16 |
-
- Savat va buyurtma berish tizimi
|
| 17 |
-
- Admin panel
|
| 18 |
-
- Broadcast va Excel export
|
| 19 |
-
- Rate limiting va xavfsizlik
|
|
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
# MTXtyle - Telegram Bot
|
| 13 |
|
| 14 |
Kiyim va aksessuarlar do'koni uchun Telegram bot.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,71 +1,77 @@
|
|
| 1 |
"""
|
| 2 |
-
MTXtyle Bot - Hugging Face Spaces Entry Point
|
| 3 |
-
Runs
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
import threading
|
| 7 |
-
import time
|
| 8 |
import subprocess
|
| 9 |
import sys
|
| 10 |
import os
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
bot_status = "starting"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
self.send_response(200)
|
| 18 |
-
self.send_header("Content-type", "text/html; charset=utf-8")
|
| 19 |
-
self.end_headers()
|
| 20 |
-
html = f"""
|
| 21 |
-
<html><body style="font-family:sans-serif;text-align:center;padding:50px;">
|
| 22 |
-
<h1>π€ MTXtyle Bot</h1>
|
| 23 |
-
<p>Status: {bot_status}</p>
|
| 24 |
-
</body></html>
|
| 25 |
-
"""
|
| 26 |
-
self.wfile.write(html.encode("utf-8"))
|
| 27 |
-
|
| 28 |
-
def log_message(self, format, *args):
|
| 29 |
-
pass
|
| 30 |
|
| 31 |
def run_bot():
|
| 32 |
-
global bot_status
|
| 33 |
|
| 34 |
-
# Check BOT_TOKEN
|
| 35 |
token = os.getenv("BOT_TOKEN")
|
| 36 |
if not token:
|
| 37 |
-
bot_status = "β BOT_TOKEN
|
| 38 |
-
|
| 39 |
-
print("Please add BOT_TOKEN in your HuggingFace Space Settings -> Secrets")
|
| 40 |
return
|
| 41 |
|
| 42 |
-
|
| 43 |
-
max_retries = 10
|
| 44 |
for attempt in range(1, max_retries + 1):
|
| 45 |
-
bot_status = f"π
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
time.sleep(5 * attempt) # Increasing delay: 5s, 10s, 15s...
|
| 50 |
|
| 51 |
-
result = subprocess.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if result.returncode == 0:
|
| 54 |
-
bot_status = "β
|
| 55 |
break
|
| 56 |
else:
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
-
bot_status = "β
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
| 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 on port 7860.
|
| 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, bot_log
|
| 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 |
+
max_retries = 5
|
|
|
|
| 26 |
for attempt in range(1, max_retries + 1):
|
| 27 |
+
bot_status = f"π Ishga tushirilmoqda... (urinish {attempt}/{max_retries})"
|
| 28 |
+
bot_log.append(f"[Attempt {attempt}] Starting bot...")
|
| 29 |
|
| 30 |
+
time.sleep(3)
|
|
|
|
| 31 |
|
| 32 |
+
result = subprocess.run(
|
| 33 |
+
[sys.executable, "bot.py"],
|
| 34 |
+
capture_output=True,
|
| 35 |
+
text=True
|
| 36 |
+
)
|
| 37 |
|
| 38 |
if result.returncode == 0:
|
| 39 |
+
bot_status = "β
Bot ishlayapti!"
|
| 40 |
break
|
| 41 |
else:
|
| 42 |
+
error_msg = result.stderr[-500:] if result.stderr else "Unknown error"
|
| 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 |
+
log_text = "\n".join(bot_log[-20:]) if bot_log else "Loglar hali yo'q..."
|
| 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)
|
| 59 |
+
bot_thread.start()
|
| 60 |
+
|
| 61 |
+
# Gradio Interface
|
| 62 |
+
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 |
+
with gr.Row():
|
| 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=check_status, outputs=[status_box, log_box])
|
| 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)
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|