BasicHfBot / app /main.py
understanding's picture
Create app/main.py
36bd37c verified
raw
history blame
846 Bytes
from __future__ import annotations
import asyncio
from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.config import load_config
from app.cf_api import CFClient
from bot.client import build_bot
from bot.handlers import register_handlers
cfg = load_config()
cf = CFClient(cfg.WORKER1_URL, cfg.WORKER2_URL, cfg.BOT_BACKEND_KEY, cfg.HF_API_KEY)
bot = build_bot(cfg)
@asynccontextmanager
async def lifespan(app: FastAPI):
# start bot
await register_handlers(bot, cfg, cf)
await bot.start()
yield
# stop bot
await bot.stop()
await cf.close()
app = FastAPI(lifespan=lifespan)
@app.get("/")
async def root():
return {
"ok": True,
"service": "yt-uploader-bot",
"bot_username": cfg.BOT_USERNAME,
}
@app.get("/health")
async def health():
return {"ok": True}