from concurrent.futures import ThreadPoolExecutor

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from loguru import logger

from routers import get_related_words
from routers import script_config
from routers import tengxunyun_server
from script_score.lstm_network import SentimentNet
from script_score.evaluate_script import router as evaluate_script_router


logger.remove()  # 删去 import logger之后自动产生的handler，不删除的话会出现重复输出的现象
logger.add("/data/pythonProject/video_to_word/logs/main_server.{time:YYYY-MM-DD}.log",
           rotation="00:00",
           format="{time:YYYY-MM-DD HH:mm:ss,SSS} [{process}] [{thread}] {level} {file} {line} - {message}",
           level="INFO")

threadPool = ThreadPoolExecutor(max_workers=4)
app = FastAPI()
origins = [
    "http://192.168.0.195:9001",
    "http://192.168.6.220:3000",
    "http://192.168.1.91:3000",
    "http://192.168.1.34",
    "http://192.168.1.34:8000",
    "http://192.168.1.105",
    "http://192.168.1.105:3000",
    "http://111.206.86.186",
    "http://111.206.86.186:3000",
    "http://adsp.tjyourong.com.cn",
    "http://adsp.tjyourong.com.cn:3000",
    "http://adsp.c-top.com.cn",
    "http://adsp.c-top.com.cn:3000"
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(get_related_words.router)
app.include_router(tengxunyun_server.router)
app.include_router(script_config.router)
app.include_router(evaluate_script_router)

if __name__ == '__main__':
    uvicorn.run(app='main:app', host="0.0.0.0", port=31013, reload=True, debug=True)
# gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker #线上启动命令
