Spaces:
Sleeping
Sleeping
# main.py | |
import uvicorn | |
from fastapi import FastAPI | |
from fastapi.responses import HTMLResponse | |
import logging | |
import asyncio | |
import bot # import your bot.py file | |
app = FastAPI() | |
async def startup_event(): | |
logging.basicConfig(level=logging.INFO) | |
logging.info("Starting bot polling in background...") | |
asyncio.create_task(bot.run_bot()) | |
def health(): | |
return {"status": "ok"} | |
def home(): | |
active_workers = bot.config.CONCURRENT_WORKERS | |
running_batches = len(bot.BATCH_JOBS) | |
queued_tasks = bot.TASK_QUEUE.qsize() | |
html = f""" | |
<html> | |
<head><title>Terabox Bot Status</title></head> | |
<body> | |
<h1>Terabox Bot Status</h1> | |
<p><b>Bot Username:</b> {bot.bot_username or 'Unknown'}</p> | |
<p><b>Active Workers:</b> {active_workers}</p> | |
<p><b>Running Batches:</b> {running_batches}</p> | |
<p><b>Queued Tasks:</b> {queued_tasks}</p> | |
<p><b>Health:</b> <a href="/health">/health</a></p> | |
</body> | |
</html> | |
""" | |
return HTMLResponse(content=html) | |
if __name__ == "__main__": | |
uvicorn.run(app, host="0.0.0.0", port=7860) | |