修改了部分模块,适配于远程服务器
This commit is contained in:
parent
def6de204f
commit
821d023734
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
|||||||
/assets/
|
/assets/
|
||||||
/resource/data/
|
/resource/data/
|
||||||
/tests/output/
|
/tests/output/
|
||||||
|
/data/
|
||||||
BIN
api/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
api/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/dependencies.cpython-310.pyc
Normal file
BIN
api/__pycache__/dependencies.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/main.cpython-310.pyc
Normal file
BIN
api/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/content_integration.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/content_integration.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/document.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/document.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/integration.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/integration.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/poster.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/poster.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/models/__pycache__/tweet.cpython-310.pyc
Normal file
BIN
api/models/__pycache__/tweet.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/content_integration.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/content_integration.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/data.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/data.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/document.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/document.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/integration.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/integration.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/poster.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/poster.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/prompt.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/prompt.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/routers/__pycache__/tweet.cpython-310.pyc
Normal file
BIN
api/routers/__pycache__/tweet.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
api/services/__pycache__/database_service.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/database_service.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/document_service.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/document_service.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/integration_service.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/integration_service.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/poster.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/poster.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/prompt_builder.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/prompt_builder.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/prompt_service.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/prompt_service.cpython-310.pyc
Normal file
Binary file not shown.
BIN
api/services/__pycache__/tweet.cpython-310.pyc
Normal file
BIN
api/services/__pycache__/tweet.cpython-310.pyc
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"user": "root",
|
"user": "root",
|
||||||
"password": "password",
|
"password": "civmek-rezTed-0hovre",
|
||||||
"database": "travel_content",
|
"database": "travel_content",
|
||||||
"port": 3306,
|
"port": 3306,
|
||||||
"charset": "utf8mb4"
|
"charset": "utf8mb4"
|
||||||
|
|||||||
Binary file not shown.
BIN
core/__pycache__/cookie_manager.cpython-310.pyc
Normal file
BIN
core/__pycache__/cookie_manager.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/document_adapter.cpython-310.pyc
Normal file
BIN
core/__pycache__/document_adapter.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/media_manager.cpython-310.pyc
Normal file
BIN
core/__pycache__/media_manager.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/models.cpython-310.pyc
Normal file
BIN
core/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/__pycache__/xhs_adapter.cpython-310.pyc
Normal file
BIN
core/__pycache__/xhs_adapter.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
core/document/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
core/document/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/document/__pycache__/content_integrator.cpython-310.pyc
Normal file
BIN
core/document/__pycache__/content_integrator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/document/__pycache__/content_transformer.cpython-310.pyc
Normal file
BIN
core/document/__pycache__/content_transformer.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/document/__pycache__/text_extractor.cpython-310.pyc
Normal file
BIN
core/document/__pycache__/text_extractor.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/exception/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
core/exception/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/exception/__pycache__/exceptions.cpython-310.pyc
Normal file
BIN
core/exception/__pycache__/exceptions.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/xhs_spider/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
core/xhs_spider/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/xhs_spider/__pycache__/main.cpython-310.pyc
Normal file
BIN
core/xhs_spider/__pycache__/main.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/xhs_spider/apis/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
core/xhs_spider/apis/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
core/xhs_spider/apis/__pycache__/xhs_pc_apis.cpython-310.pyc
Normal file
BIN
core/xhs_spider/apis/__pycache__/xhs_pc_apis.cpython-310.pyc
Normal file
Binary file not shown.
BIN
core/xhs_spider/xhs_utils/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
core/xhs_spider/xhs_utils/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
core/xhs_spider/xhs_utils/__pycache__/data_util.cpython-310.pyc
Normal file
BIN
core/xhs_spider/xhs_utils/__pycache__/data_util.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
core/xhs_spider/xhs_utils/__pycache__/xhs_util.cpython-310.pyc
Normal file
BIN
core/xhs_spider/xhs_utils/__pycache__/xhs_util.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
poster/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/__pycache__/utils.cpython-310.pyc
Normal file
BIN
poster/__pycache__/utils.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/templates/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
poster/templates/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/templates/__pycache__/base_template.cpython-310.pyc
Normal file
BIN
poster/templates/__pycache__/base_template.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/templates/__pycache__/business_template.cpython-310.pyc
Normal file
BIN
poster/templates/__pycache__/business_template.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/templates/__pycache__/collage_template.cpython-310.pyc
Normal file
BIN
poster/templates/__pycache__/collage_template.cpython-310.pyc
Normal file
Binary file not shown.
BIN
poster/templates/__pycache__/vibrant_template.cpython-310.pyc
Normal file
BIN
poster/templates/__pycache__/vibrant_template.cpython-310.pyc
Normal file
Binary file not shown.
125
run_api.py
125
run_api.py
@ -2,28 +2,127 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
TravelContentCreator API服务启动脚本
|
TravelContentCreator API 服务启动脚本(生产环境优化版)
|
||||||
|
|
||||||
|
- 基于 uvicorn 官方 API 启动 FastAPI 应用。
|
||||||
|
- 默认按「2 * CPU + 1」规则自动计算 worker 数,以充分利用多核性能。
|
||||||
|
- 可选择使用 uvloop 作为事件循环,提升 I/O 性能(如未安装 uvloop 会自动降级)。
|
||||||
|
- 支持通过环境变量或命令行参数覆盖默认配置,方便容器化部署。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import uvicorn
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
if __name__ == "__main__":
|
import uvicorn
|
||||||
# 配置命令行参数
|
|
||||||
parser = argparse.ArgumentParser(description="TravelContentCreator API服务")
|
|
||||||
parser.add_argument("--host", default="0.0.0.0", help="监听主机地址")
|
def build_arg_parser() -> argparse.ArgumentParser:
|
||||||
parser.add_argument("--port", type=int, default=8000, help="监听端口")
|
"""构造命令行解析器"""
|
||||||
parser.add_argument("--reload", action="store_true", help="是否启用热重载")
|
cpu_cores = multiprocessing.cpu_count()
|
||||||
parser.add_argument("--log-level", default="info", help="日志级别")
|
default_workers = cpu_cores * 2 + 1
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="TravelContentCreator API 服务(生产环境)")
|
||||||
|
parser.add_argument("--host", default=os.getenv("HOST", "0.0.0.0"), help="监听主机地址")
|
||||||
|
parser.add_argument(
|
||||||
|
"--port",
|
||||||
|
type=int,
|
||||||
|
default=int(os.getenv("PORT", 8000)),
|
||||||
|
help="监听端口",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--workers",
|
||||||
|
type=int,
|
||||||
|
default=int(os.getenv("WORKERS", default_workers)),
|
||||||
|
help="worker 进程数,默认 2*CPU + 1",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--log-level",
|
||||||
|
default=os.getenv("LOG_LEVEL", "info"),
|
||||||
|
choices=[
|
||||||
|
"critical",
|
||||||
|
"error",
|
||||||
|
"warning",
|
||||||
|
"info",
|
||||||
|
"debug",
|
||||||
|
"trace",
|
||||||
|
],
|
||||||
|
help="日志级别",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--proxy-headers",
|
||||||
|
action="store_true",
|
||||||
|
help="信任代理头(例如部署在 Nginx / Traefik 之后时开启)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--loop",
|
||||||
|
default=os.getenv("LOOP", "uvloop"),
|
||||||
|
choices=["uvloop", "asyncio"],
|
||||||
|
help="事件循环实现(uvloop 未安装时自动降级到 asyncio)",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--timeout-keep-alive",
|
||||||
|
type=int,
|
||||||
|
default=int(os.getenv("TIMEOUT_KEEP_ALIVE", 5)),
|
||||||
|
help="Keep-Alive 超时时间 (秒)",
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logging(log_level: str = "info") -> None:
|
||||||
|
"""初始化日志配置"""
|
||||||
|
logging.basicConfig(
|
||||||
|
level=getattr(logging, log_level.upper(), logging.INFO),
|
||||||
|
format="%(asctime)s | %(levelname)s | %(process)d | %(name)s | %(message)s",
|
||||||
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
|
stream=sys.stdout,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def maybe_install_uvloop(enable: bool) -> None:
|
||||||
|
"""若选择 uvloop 并且可用,则安装之"""
|
||||||
|
if not enable:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
import uvloop # type: ignore
|
||||||
|
|
||||||
|
uvloop.install()
|
||||||
|
logging.getLogger(__name__).info("uvloop 已启用")
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
logging.getLogger(__name__).warning("未检测到 uvloop,降级使用默认 asyncio 事件循环")
|
||||||
|
|
||||||
|
|
||||||
|
def run() -> None: # noqa: C901 # (函数较长但在此处可接受)
|
||||||
|
parser = build_arg_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# 启动服务
|
setup_logging(args.log_level)
|
||||||
print(f"启动API服务,地址: {args.host}:{args.port}")
|
maybe_install_uvloop(args.loop == "uvloop")
|
||||||
|
|
||||||
|
logging.getLogger(__name__).info(
|
||||||
|
"启动 API 服务: http://%s:%d | workers=%d | loop=%s",
|
||||||
|
args.host,
|
||||||
|
args.port,
|
||||||
|
args.workers,
|
||||||
|
args.loop,
|
||||||
|
)
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"api.main:app",
|
"api.main:app",
|
||||||
host=args.host,
|
host=args.host,
|
||||||
port=args.port,
|
port=args.port,
|
||||||
reload=args.reload,
|
workers=args.workers,
|
||||||
log_level=args.log_level
|
proxy_headers=args.proxy_headers,
|
||||||
|
log_level=args.log_level,
|
||||||
|
timeout_keep_alive=args.timeout_keep_alive, # type: ignore[arg-type]
|
||||||
|
loop="uvloop" if args.loop == "uvloop" else "asyncio",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
BIN
tweet/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
tweet/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tweet/__pycache__/content_generator.cpython-310.pyc
Normal file
BIN
tweet/__pycache__/content_generator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tweet/__pycache__/content_judger.cpython-310.pyc
Normal file
BIN
tweet/__pycache__/content_judger.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tweet/__pycache__/topic_generator.cpython-310.pyc
Normal file
BIN
tweet/__pycache__/topic_generator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tweet/__pycache__/topic_parser.cpython-310.pyc
Normal file
BIN
tweet/__pycache__/topic_parser.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
utils/__pycache__/image_processor.cpython-310.pyc
Normal file
BIN
utils/__pycache__/image_processor.cpython-310.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/prompts.cpython-310.pyc
Normal file
BIN
utils/__pycache__/prompts.cpython-310.pyc
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user