31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""M2: 导入 73 场 SRT 到直播原文库(后台任务)"""
|
|
import sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, r'C:\Users\xinmiclaw\Desktop\雅文内容创造工作台\server')
|
|
|
|
from sqlmodel import Session, select
|
|
from app.db import engine, init_db
|
|
from app.models import KnowledgeBase
|
|
from app.rag import pipeline
|
|
|
|
init_db()
|
|
srt_files = []
|
|
for p in Path(r'E:\03_直播素材\直播合集').rglob('*.srt'):
|
|
srt_files.append(str(p))
|
|
print(f"找到 {len(srt_files)} 个 SRT")
|
|
|
|
with Session(engine) as s:
|
|
kb = s.exec(select(KnowledgeBase).where(KnowledgeBase.name == "直播原文库")).first()
|
|
if not kb:
|
|
kb = KnowledgeBase(name="直播原文库", desc="73场雅文直播SRT转录(573万字)")
|
|
s.add(kb); s.commit(); s.refresh(kb)
|
|
kid = kb.id
|
|
print(f"库 id={kid}(复用),开始导入(分块+向量化,预计 30 分钟)...")
|
|
done = [0]
|
|
def cb(name, n):
|
|
done[0] += 1
|
|
if done[0] % 10 == 0:
|
|
print(f" 进度: {done[0]}/{len(srt_files)} 文件,累计 {n} 块", flush=True)
|
|
res = pipeline.import_kb_files(s, kid, srt_files, progress_cb=cb)
|
|
print("完成:", res)
|