This repository was archived by the owner on Jan 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (38 loc) · 1.54 KB
/
Copy pathmain.py
File metadata and controls
53 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations
import asyncio
import logging
from aiogram import Bot, Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from app.bot import setup_routers
from app.config import get_settings
from app.db.session import init_engine
from app.logging import configure_logging
from app.dependencies import set_generation_service, set_model_registry, set_storage_service
from app.services.generation import GenerationService
from app.services.model_registry import ModelRegistry
from app.services.storage import StorageService
async def _on_startup() -> None:
configure_logging()
settings = get_settings()
await init_engine()
model_registry = ModelRegistry()
if not model_registry.list_models():
logging.warning("No diffusion models were discovered. /draw will be unavailable until models are added.")
generation_service = GenerationService(model_registry)
storage_service = StorageService()
set_model_registry(model_registry)
set_generation_service(generation_service)
set_storage_service(storage_service)
bot = Bot(token=settings.bot_token, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
dispatcher = Dispatcher()
setup_routers(dispatcher)
await bot.delete_webhook(drop_pending_updates=True)
await dispatcher.start_polling(bot)
def main() -> None:
try:
asyncio.run(_on_startup())
except (KeyboardInterrupt, SystemExit):
logging.info("Bot stopped.")
if __name__ == "__main__":
main()