标注一下,这是一个可以启动的版本
This commit is contained in:
parent
b0379e64c9
commit
434e1af3e8
@ -11,7 +11,7 @@ Mysql 数据库配置项
|
|||||||
连接引擎官方文档:https://www.osgeo.cn/sqlalchemy/core/engines.html
|
连接引擎官方文档:https://www.osgeo.cn/sqlalchemy/core/engines.html
|
||||||
数据库链接配置说明:mysql+asyncmy://数据库用户名:数据库密码@数据库地址:数据库端口/数据库名称
|
数据库链接配置说明:mysql+asyncmy://数据库用户名:数据库密码@数据库地址:数据库端口/数据库名称
|
||||||
"""
|
"""
|
||||||
SQLALCHEMY_DATABASE_URL = "mysql+asyncmy://root:root@127.0.0.1:3306/kinit"
|
SQLALCHEMY_DATABASE_URL = "mysql+asyncmy://root:root@127.0.0.1:3306/aicheck-dev"
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -31,22 +31,8 @@ MONGO_DB_URL = f"mongodb://kinit:123456@177.8.0.6:27017/?authSource={MONGO_DB_NA
|
|||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
阿里云对象存储OSS配置
|
华为云对象存储OBS设置
|
||||||
阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
||||||
yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
|
||||||
* [accessKeyId] {String}:通过阿里云控制台创建的AccessKey。
|
|
||||||
* [accessKeySecret] {String}:通过阿里云控制台创建的AccessSecret。
|
|
||||||
* [bucket] {String}:通过控制台或PutBucket创建的bucket。
|
|
||||||
* [endpoint] {String}:bucket所在的区域, 默认oss-cn-hangzhou。
|
|
||||||
"""
|
"""
|
||||||
ALIYUN_OSS = {
|
|
||||||
"accessKeyId": "accessKeyId",
|
|
||||||
"accessKeySecret": "accessKeySecret",
|
|
||||||
"endpoint": "endpoint",
|
|
||||||
"bucket": "bucket",
|
|
||||||
"baseUrl": "baseUrl"
|
|
||||||
}
|
|
||||||
|
|
||||||
HUAWEI_OBS = {
|
HUAWEI_OBS = {
|
||||||
"AccessKeyID": "HPUAICKSMPQP4XSATCLX",
|
"AccessKeyID": "HPUAICKSMPQP4XSATCLX",
|
||||||
"SecretAccessKey": "DoAL1RWydNwSQRsodS4c34nC0XyXy6TAsetVMasy",
|
"SecretAccessKey": "DoAL1RWydNwSQRsodS4c34nC0XyXy6TAsetVMasy",
|
||||||
|
@ -11,7 +11,7 @@ Mysql 数据库配置项
|
|||||||
连接引擎官方文档:https://www.osgeo.cn/sqlalchemy/core/engines.html
|
连接引擎官方文档:https://www.osgeo.cn/sqlalchemy/core/engines.html
|
||||||
数据库链接配置说明:mysql+asyncmy://数据库用户名:数据库密码@数据库地址:数据库端口/数据库名称
|
数据库链接配置说明:mysql+asyncmy://数据库用户名:数据库密码@数据库地址:数据库端口/数据库名称
|
||||||
"""
|
"""
|
||||||
SQLALCHEMY_DATABASE_URL = "mysql+asyncmy://root:123456@177.8.0.7:3306/kinit"
|
SQLALCHEMY_DATABASE_URL = "mysql+asyncmy://root:123456@177.8.0.7:3306/aicheck-pro"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Redis 数据库配置
|
Redis 数据库配置
|
||||||
@ -24,28 +24,14 @@ REDIS_DB_URL = "redis://:123456@177.8.0.5:6379/1"
|
|||||||
MongoDB 数据库配置
|
MongoDB 数据库配置
|
||||||
格式:mongodb://用户名:密码@地址:端口/?authSource=数据库名称
|
格式:mongodb://用户名:密码@地址:端口/?authSource=数据库名称
|
||||||
"""
|
"""
|
||||||
MONGO_DB_ENABLE = True
|
MONGO_DB_ENABLE = False
|
||||||
MONGO_DB_NAME = "kinit"
|
MONGO_DB_NAME = "kinit"
|
||||||
MONGO_DB_URL = f"mongodb://kinit:123456@177.8.0.6:27017/?authSource={MONGO_DB_NAME}"
|
MONGO_DB_URL = f"mongodb://kinit:123456@177.8.0.6:27017/?authSource={MONGO_DB_NAME}"
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
阿里云对象存储OSS配置
|
华为云对象存储OBS设置
|
||||||
阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
|
|
||||||
yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
|
|
||||||
* [accessKeyId] {String}:通过阿里云控制台创建的AccessKey。
|
|
||||||
* [accessKeySecret] {String}:通过阿里云控制台创建的AccessSecret。
|
|
||||||
* [bucket] {String}:通过控制台或PutBucket创建的bucket。
|
|
||||||
* [endpoint] {String}:bucket所在的区域, 默认oss-cn-hangzhou。
|
|
||||||
"""
|
"""
|
||||||
ALIYUN_OSS = {
|
|
||||||
"accessKeyId": "accessKeyId",
|
|
||||||
"accessKeySecret": "accessKeySecret",
|
|
||||||
"endpoint": "endpoint",
|
|
||||||
"bucket": "bucket",
|
|
||||||
"baseUrl": "baseUrl"
|
|
||||||
}
|
|
||||||
|
|
||||||
HUAWEI_OBS = {
|
HUAWEI_OBS = {
|
||||||
"AccessKeyID": "HPUAICKSMPQP4XSATCLX",
|
"AccessKeyID": "HPUAICKSMPQP4XSATCLX",
|
||||||
"SecretAccessKey": "DoAL1RWydNwSQRsodS4c34nC0XyXy6TAsetVMasy",
|
"SecretAccessKey": "DoAL1RWydNwSQRsodS4c34nC0XyXy6TAsetVMasy",
|
||||||
@ -53,6 +39,7 @@ HUAWEI_OBS = {
|
|||||||
"bucketName": "aicheckv2"
|
"bucketName": "aicheckv2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
获取IP地址归属地
|
获取IP地址归属地
|
||||||
文档:https://user.ip138.com/ip/doc
|
文档:https://user.ip138.com/ip/doc
|
||||||
|
@ -83,7 +83,7 @@ STATIC_URL:路由访问
|
|||||||
STATIC_ROOT:静态文件目录绝对路径
|
STATIC_ROOT:静态文件目录绝对路径
|
||||||
官方文档:https://fastapi.tiangolo.com/tutorial/static-files/
|
官方文档:https://fastapi.tiangolo.com/tutorial/static-files/
|
||||||
"""
|
"""
|
||||||
STATIC_ENABLE = True
|
STATIC_ENABLE = False
|
||||||
STATIC_URL = "/media"
|
STATIC_URL = "/media"
|
||||||
STATIC_DIR = "static"
|
STATIC_DIR = "static"
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_DIR)
|
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_DIR)
|
||||||
|
@ -6,10 +6,9 @@
|
|||||||
# @IDE : PyCharm
|
# @IDE : PyCharm
|
||||||
# @desc : 路由,视图文件
|
# @desc : 路由,视图文件
|
||||||
|
|
||||||
import service
|
|
||||||
from . import schemas, crud, params
|
|
||||||
from core.dependencies import IdList
|
from core.dependencies import IdList
|
||||||
from core.database import redis_getter
|
from core.database import redis_getter
|
||||||
|
from . import schemas, crud, params, service
|
||||||
from utils.websocket_server import room_manager
|
from utils.websocket_server import room_manager
|
||||||
from apps.business.train.crud import ProjectTrainDal
|
from apps.business.train.crud import ProjectTrainDal
|
||||||
from apps.vadmin.auth.utils.current import AllUserAuth
|
from apps.vadmin.auth.utils.current import AllUserAuth
|
||||||
|
@ -3,12 +3,11 @@
|
|||||||
# @version : 1.0
|
# @version : 1.0
|
||||||
# @Create Time : 2025/04/03 10:32
|
# @Create Time : 2025/04/03 10:32
|
||||||
# @File : views.py
|
# @File : views.py
|
||||||
from . import models, schemas, crud
|
from . import models, schemas, crud, service
|
||||||
from apps.business.project.crud import ProjectInfoDal, ProjectImageDal
|
|
||||||
from utils.response import SuccessResponse, ErrorResponse
|
|
||||||
from apps.vadmin.auth.utils.current import AllUserAuth
|
from apps.vadmin.auth.utils.current import AllUserAuth
|
||||||
from apps.vadmin.auth.utils.validation.auth import Auth
|
from apps.vadmin.auth.utils.validation.auth import Auth
|
||||||
import service
|
from utils.response import SuccessResponse, ErrorResponse
|
||||||
|
from apps.business.project.crud import ProjectInfoDal, ProjectImageDal
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
|
@ -70,7 +70,7 @@ async def connect_redis(app: FastAPI, status: bool):
|
|||||||
print("Redis 连接成功")
|
print("Redis 连接成功")
|
||||||
# 数据初始化
|
# 数据初始化
|
||||||
is_gpu = torch.cuda.is_available()
|
is_gpu = torch.cuda.is_available()
|
||||||
rd.set('is_gpu', str(is_gpu))
|
await rd.set('is_gpu', str(is_gpu))
|
||||||
else:
|
else:
|
||||||
print("Redis 连接失败")
|
print("Redis 连接失败")
|
||||||
except AuthenticationError as e:
|
except AuthenticationError as e:
|
||||||
|
72
main.py
72
main.py
@ -11,22 +11,17 @@ FastApi Github:https://github.com/tiangolo/fastapi
|
|||||||
Typer 官方文档:https://typer.tiangolo.com/
|
Typer 官方文档:https://typer.tiangolo.com/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
import uvicorn
|
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
|
||||||
from application import settings
|
|
||||||
from application import urls
|
from application import urls
|
||||||
from starlette.staticfiles import StaticFiles # 依赖安装:pip install aiofiles
|
|
||||||
from core.websocket_app import websocket_config
|
|
||||||
from core.exception import register_exception
|
|
||||||
import typer
|
|
||||||
from scripts.initialize.initialize import InitializeData, Environment
|
|
||||||
import asyncio
|
|
||||||
from scripts.create_app.main import CreateApp
|
|
||||||
from core.event import lifespan
|
from core.event import lifespan
|
||||||
|
from application import settings
|
||||||
from utils.tools import import_modules
|
from utils.tools import import_modules
|
||||||
|
from core.exception import register_exception
|
||||||
|
from core.websocket_app import websocket_config
|
||||||
|
|
||||||
shell_app = typer.Typer()
|
import typer
|
||||||
|
import uvicorn
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
@ -39,7 +34,7 @@ def create_app():
|
|||||||
"""
|
"""
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="aicheckv2-api",
|
title="aicheckv2-api",
|
||||||
description="aicheckv2.1版本,在之前v2.0的版本上找一个框架对项目,用户和部门进行统一管理",
|
description="aicheckv2.0的后台api",
|
||||||
version=settings.VERSION,
|
version=settings.VERSION,
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
docs_url=None,
|
docs_url=None,
|
||||||
@ -57,20 +52,14 @@ def create_app():
|
|||||||
allow_methods=settings.ALLOW_METHODS,
|
allow_methods=settings.ALLOW_METHODS,
|
||||||
allow_headers=settings.ALLOW_HEADERS
|
allow_headers=settings.ALLOW_HEADERS
|
||||||
)
|
)
|
||||||
# 挂在静态目录
|
|
||||||
if settings.STATIC_ENABLE:
|
|
||||||
app.mount(settings.STATIC_URL, app=StaticFiles(directory=settings.STATIC_ROOT))
|
|
||||||
# 引入应用中的路由
|
# 引入应用中的路由
|
||||||
for url in urls.urlpatterns:
|
for url in urls.urlpatterns:
|
||||||
app.include_router(url["ApiRouter"], prefix=url["prefix"], tags=url["tags"])
|
app.include_router(url["ApiRouter"], prefix=url["prefix"], tags=url["tags"])
|
||||||
# 配置接口文档静态资源
|
|
||||||
# custom_api_docs(app)
|
|
||||||
# 开启websocket
|
# 开启websocket
|
||||||
websocket_config(app)
|
websocket_config(app)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
@shell_app.command()
|
|
||||||
def run(
|
def run(
|
||||||
host: str = typer.Option(default='0.0.0.0', help='监听主机IP,默认开放给本网络所有主机'),
|
host: str = typer.Option(default='0.0.0.0', help='监听主机IP,默认开放给本网络所有主机'),
|
||||||
port: int = typer.Option(default=9000, help='监听端口')
|
port: int = typer.Option(default=9000, help='监听端口')
|
||||||
@ -84,48 +73,5 @@ def run(
|
|||||||
uvicorn.run(app='main:create_app', host=host, port=port, lifespan="on", factory=True)
|
uvicorn.run(app='main:create_app', host=host, port=port, lifespan="on", factory=True)
|
||||||
|
|
||||||
|
|
||||||
@shell_app.command()
|
|
||||||
def init(env: Environment = Environment.pro):
|
|
||||||
"""
|
|
||||||
初始化数据
|
|
||||||
|
|
||||||
在执行前一定要确认要操作的环境与application/settings.DEBUG 设置的环境是一致的,
|
|
||||||
不然会导致创建表和生成数据不在一个数据库中!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
比如要初始化开发环境,那么env参数应该为 dev,并且 application/settings.DEBUG 应该 = True
|
|
||||||
比如要初始化生产环境,那么env参数应该为 pro,并且 application/settings.DEBUG 应该 = False
|
|
||||||
|
|
||||||
:param env: 数据库环境
|
|
||||||
"""
|
|
||||||
print("开始初始化数据")
|
|
||||||
data = InitializeData()
|
|
||||||
asyncio.run(data.run(env))
|
|
||||||
|
|
||||||
|
|
||||||
@shell_app.command()
|
|
||||||
def migrate(env: Environment = Environment.pro):
|
|
||||||
"""
|
|
||||||
将模型迁移到数据库,更新数据库表结构
|
|
||||||
|
|
||||||
:param env: 数据库环境
|
|
||||||
"""
|
|
||||||
print("开始更新数据库表")
|
|
||||||
InitializeData.migrate_model(env)
|
|
||||||
|
|
||||||
|
|
||||||
@shell_app.command()
|
|
||||||
def init_app(path: str):
|
|
||||||
"""
|
|
||||||
自动创建初始化 APP 结构
|
|
||||||
|
|
||||||
命令例子:python main.py init-app vadmin/test
|
|
||||||
|
|
||||||
:param path: app 路径,根目录为apps,填写apps后面路径即可,例子:vadmin/auth
|
|
||||||
"""
|
|
||||||
print(f"开始创建并初始化 {path} APP")
|
|
||||||
app = CreateApp(path)
|
|
||||||
app.run()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
shell_app()
|
run(host='0.0.0.0', port=9000)
|
||||||
|
@ -35,9 +35,9 @@ except (ImportError, AssertionError):
|
|||||||
|
|
||||||
from ultralytics.utils.plotting import Annotator, colors, save_one_box
|
from ultralytics.utils.plotting import Annotator, colors, save_one_box
|
||||||
|
|
||||||
from app.util.yolov5.utils import TryExcept
|
from utils.yolov5.utils import TryExcept
|
||||||
from app.util.yolov5.utils.dataloaders import exif_transpose, letterbox
|
from utils.yolov5.utils.dataloaders import exif_transpose, letterbox
|
||||||
from app.util.yolov5.utils.general import (
|
from utils.yolov5.utils.general import (
|
||||||
LOGGER,
|
LOGGER,
|
||||||
ROOT,
|
ROOT,
|
||||||
Profile,
|
Profile,
|
||||||
@ -54,7 +54,7 @@ from app.util.yolov5.utils.general import (
|
|||||||
xyxy2xywh,
|
xyxy2xywh,
|
||||||
yaml_load,
|
yaml_load,
|
||||||
)
|
)
|
||||||
from app.util.yolov5.utils.torch_utils import copy_attr, smart_inference_mode
|
from utils.yolov5.utils.torch_utils import copy_attr, smart_inference_mode
|
||||||
|
|
||||||
|
|
||||||
def autopad(k, p=None, d=1):
|
def autopad(k, p=None, d=1):
|
||||||
@ -473,7 +473,7 @@ class DetectMultiBackend(nn.Module):
|
|||||||
# TensorFlow Lite: *.tflite
|
# TensorFlow Lite: *.tflite
|
||||||
# TensorFlow Edge TPU: *_edgetpu.tflite
|
# TensorFlow Edge TPU: *_edgetpu.tflite
|
||||||
# PaddlePaddle: *_paddle_model
|
# PaddlePaddle: *_paddle_model
|
||||||
from app.util.yolov5.models.experimental import attempt_download, attempt_load # scoped to avoid circular import
|
from utils.yolov5.models.experimental import attempt_download, attempt_load # scoped to avoid circular import
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
w = str(weights[0] if isinstance(weights, list) else weights)
|
w = str(weights[0] if isinstance(weights, list) else weights)
|
||||||
@ -661,7 +661,7 @@ class DetectMultiBackend(nn.Module):
|
|||||||
elif triton: # NVIDIA Triton Inference Server
|
elif triton: # NVIDIA Triton Inference Server
|
||||||
LOGGER.info(f"Using {w} as Triton Inference Server...")
|
LOGGER.info(f"Using {w} as Triton Inference Server...")
|
||||||
check_requirements("tritonclient[all]")
|
check_requirements("tritonclient[all]")
|
||||||
from app.util.yolov5.utils.triton import TritonRemoteModel
|
from utils.yolov5.utils.triton import TritonRemoteModel
|
||||||
|
|
||||||
model = TritonRemoteModel(url=w)
|
model = TritonRemoteModel(url=w)
|
||||||
nhwc = model.runtime.startswith("tensorflow")
|
nhwc = model.runtime.startswith("tensorflow")
|
||||||
@ -780,7 +780,7 @@ class DetectMultiBackend(nn.Module):
|
|||||||
Example: path='path/to/model.onnx' -> type=onnx
|
Example: path='path/to/model.onnx' -> type=onnx
|
||||||
"""
|
"""
|
||||||
# types = [pt, jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle]
|
# types = [pt, jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle]
|
||||||
from app.util.yolov5.utils.downloads import is_url
|
from utils.yolov5.utils.downloads import is_url
|
||||||
|
|
||||||
sf = list(export_formats().Suffix) # export suffixes
|
sf = list(export_formats().Suffix) # export suffixes
|
||||||
if not is_url(p, check=False):
|
if not is_url(p, check=False):
|
||||||
|
@ -7,7 +7,7 @@ import numpy as np
|
|||||||
import torch
|
import torch
|
||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
|
|
||||||
from app.util.yolov5.utils.downloads import attempt_download
|
from utils.yolov5.utils.downloads import attempt_download
|
||||||
|
|
||||||
|
|
||||||
class Sum(nn.Module):
|
class Sum(nn.Module):
|
||||||
@ -91,7 +91,7 @@ def attempt_load(weights, device=None, inplace=True, fuse=True):
|
|||||||
|
|
||||||
Example inputs: weights=[a,b,c] or a single model weights=[a] or weights=a.
|
Example inputs: weights=[a,b,c] or a single model weights=[a] or weights=a.
|
||||||
"""
|
"""
|
||||||
from app.util.yolov5.models.yolo import Detect, Model
|
from utils.yolov5.models.yolo import Detect, Model
|
||||||
|
|
||||||
model = Ensemble()
|
model = Ensemble()
|
||||||
for w in weights if isinstance(weights, list) else [weights]:
|
for w in weights if isinstance(weights, list) else [weights]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user