Update bot.py
Browse files
bot.py
CHANGED
@@ -4,6 +4,7 @@ from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, fil
|
|
4 |
import os
|
5 |
import time
|
6 |
import threading
|
|
|
7 |
|
8 |
# Replace with your actual Hugging Face Space backend URL
|
9 |
BACKEND_URL = "https://dragxd-host.hf.space"
|
@@ -75,7 +76,7 @@ async def deploy(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
75 |
deploy_id = resp.json()["deploy_id"]
|
76 |
await update.message.reply_text(f"Deployment started! ID: {deploy_id}\nStreaming logs:")
|
77 |
|
78 |
-
def poll_logs():
|
79 |
last_line = 0
|
80 |
finished = False
|
81 |
while not finished:
|
@@ -87,17 +88,17 @@ async def deploy(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
87 |
status = data.get("status", "unknown")
|
88 |
if logs:
|
89 |
for log in logs:
|
90 |
-
|
91 |
last_line = data.get("next_line", last_line)
|
92 |
if status != "deploying":
|
93 |
finished = True
|
94 |
-
|
95 |
break
|
96 |
-
|
97 |
except Exception as e:
|
98 |
-
|
99 |
break
|
100 |
-
|
101 |
|
102 |
def main():
|
103 |
TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN") # Set your bot token as env variable
|
|
|
4 |
import os
|
5 |
import time
|
6 |
import threading
|
7 |
+
import asyncio
|
8 |
|
9 |
# Replace with your actual Hugging Face Space backend URL
|
10 |
BACKEND_URL = "https://dragxd-host.hf.space"
|
|
|
76 |
deploy_id = resp.json()["deploy_id"]
|
77 |
await update.message.reply_text(f"Deployment started! ID: {deploy_id}\nStreaming logs:")
|
78 |
|
79 |
+
async def poll_logs():
|
80 |
last_line = 0
|
81 |
finished = False
|
82 |
while not finished:
|
|
|
88 |
status = data.get("status", "unknown")
|
89 |
if logs:
|
90 |
for log in logs:
|
91 |
+
await update.message.reply_text(log)
|
92 |
last_line = data.get("next_line", last_line)
|
93 |
if status != "deploying":
|
94 |
finished = True
|
95 |
+
await update.message.reply_text(f"Deployment finished with status: {status}")
|
96 |
break
|
97 |
+
await asyncio.sleep(2)
|
98 |
except Exception as e:
|
99 |
+
await update.message.reply_text(f"Error streaming logs: {e}")
|
100 |
break
|
101 |
+
context.application.create_task(poll_logs())
|
102 |
|
103 |
def main():
|
104 |
TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN") # Set your bot token as env variable
|