File size: 2,265 Bytes
591d823 d7d0d8e 08b3aa9 ad95bb0 252d749 07fd3f6 ff3b5ca a2b82e9 f5b43ca 62b2691 591d823 d865593 591d823 fa1fb30 7306982 bc45051 07fd3f6 bc45051 252d749 fa1fb30 d865593 d7d0d8e 252d749 62b2691 591d823 252d749 fe53703 72638cd be243ba b0b473d 591d823 252d749 0fe435d 0a00c05 72638cd 252d749 8cf933f 252d749 07fd3f6 a2b82e9 ff3b5ca f5b43ca 6c3701c |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.middleware.gzip import GZipMiddleware
from App import bot
from telethon import TelegramClient
from telethon.sessions import StringSession
from .Users.UserRoutes import user_router
from .modelInit import models, database
from .Transcription.TranscriptionRoutes import transcription_router
from .Streaming.StreamingRoutes import streaming_router
from .UserTranscriptions.UserTranscriptionsRoutes import user_transcriptions_router
from .Monitor.monitorRoutes import monitor_router
from .Embedding.EmbeddingRoutes import embeddigs_router
from .Chat.ChatRoutes import chat_router
from fastapi.middleware.cors import CORSMiddleware
from fastapi_jwt_auth.exceptions import AuthJWTException
import logging, orm
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
app = FastAPI()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(GZipMiddleware, minimum_size=1000)
@app.exception_handler(AuthJWTException)
def authjwt_exception_handler(request: Request, exc: AuthJWTException):
return JSONResponse(status_code=exc.status_code, content={"detail": exc.message})
@app.on_event("startup")
async def startup_event():
await bot.start()
# await upload_bot.start()
# await models.create_all()
# models.metadata.create_all()
if not database.is_connected:
await database.connect()
print("connected!")
@app.on_event("shutdown")
async def shutdown_event():
# bot.session.save()
# await bot.disconnect()
# await upload_bot.stop()
if not database.is_connected:
await database.disconnect()
print("shutting down!")
@app.get("/")
async def landing_page():
return {"code": 200, "message": "we are back!"}
app.include_router(user_router)
app.include_router(transcription_router)
app.include_router(streaming_router)
app.include_router(monitor_router)
app.include_router(user_transcriptions_router)
app.include_router(embeddigs_router)
app.include_router(chat_router)
|