mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-11 02:12:50 +00:00
refactor: 移除废弃脚本文件并更新项目版本至0.7.0
删除不再使用的脚本文件(check_gpu_cuda_cudnn.bat, changelog.py, main.py, release-notes.md, video_pipeline.py) 将项目版本从0.6.8更新至0.7.0,并同步更新config.example.toml中的版本号
This commit is contained in:
parent
60e01bf6f2
commit
0d49812ad2
17
changelog.py
17
changelog.py
@ -1,17 +0,0 @@
|
||||
from git_changelog.cli import build_and_render
|
||||
|
||||
# 运行这段脚本自动生成CHANGELOG.md文件
|
||||
|
||||
build_and_render(
|
||||
repository=".",
|
||||
output="CHANGELOG.md",
|
||||
convention="angular",
|
||||
provider="github",
|
||||
template="keepachangelog",
|
||||
parse_trailers=True,
|
||||
parse_refs=False,
|
||||
sections=["build", "deps", "feat", "fix", "refactor"],
|
||||
versioning="pep440",
|
||||
bump="1.1.2", # 指定bump版本
|
||||
in_place=True,
|
||||
)
|
||||
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
[app]
|
||||
project_version="0.6.8"
|
||||
project_version="0.7.0"
|
||||
|
||||
# 模型验证模式配置
|
||||
# true: 严格模式,只允许使用预定义支持列表中的模型(默认)
|
||||
|
||||
19
main.py
19
main.py
@ -1,19 +0,0 @@
|
||||
import os
|
||||
import uvicorn
|
||||
from loguru import logger
|
||||
|
||||
from app.config import config
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger.info(
|
||||
"start server, docs: http://127.0.0.1:" + str(config.listen_port) + "/docs"
|
||||
)
|
||||
os.environ["HTTP_PROXY"] = config.proxy.get("http")
|
||||
os.environ["HTTPS_PROXY"] = config.proxy.get("https")
|
||||
uvicorn.run(
|
||||
app="app.asgi:app",
|
||||
host=config.listen_host,
|
||||
port=config.listen_port,
|
||||
reload=config.reload_debug,
|
||||
log_level="warning",
|
||||
)
|
||||
@ -1 +1 @@
|
||||
0.6.8
|
||||
0.7.0
|
||||
@ -1,17 +0,0 @@
|
||||
# Release Notes
|
||||
|
||||
## Latest Changes
|
||||
|
||||
* docs(README): 更新README. PR [#138](https://github.com/linyqh/NarratoAI/pull/138) by [@linyqh](https://github.com/linyqh).
|
||||
* Dev 0.6.0. PR [#137](https://github.com/linyqh/NarratoAI/pull/137) by [@linyqh](https://github.com/linyqh).
|
||||
* Dev 0.6.0 . PR [#134](https://github.com/linyqh/NarratoAI/pull/134) by [@linyqh](https://github.com/linyqh).
|
||||
* Dev-0.3.9. PR [#73](https://github.com/linyqh/NarratoAI/pull/73) by [@linyqh](https://github.com/linyqh).
|
||||
* 0.3.9 版本发布. PR [#71](https://github.com/linyqh/NarratoAI/pull/71) by [@linyqh](https://github.com/linyqh).
|
||||
* docs: add Japanese README. PR [#66](https://github.com/linyqh/NarratoAI/pull/66) by [@eltociear](https://github.com/eltociear).
|
||||
* docs: 测试 release 2. PR [#62](https://github.com/linyqh/NarratoAI/pull/62) by [@linyqh](https://github.com/linyqh).
|
||||
* docs: 测试 release. PR [#61](https://github.com/linyqh/NarratoAI/pull/61) by [@linyqh](https://github.com/linyqh).
|
||||
* docs: 测试commit. PR [#60](https://github.com/linyqh/NarratoAI/pull/60) by [@linyqh](https://github.com/linyqh).
|
||||
* Dev. PR [#59](https://github.com/linyqh/NarratoAI/pull/59) by [@linyqh](https://github.com/linyqh).
|
||||
* 0.2.0新版预发布. PR [#37](https://github.com/linyqh/NarratoAI/pull/37) by [@linyqh](https://github.com/linyqh).
|
||||
* v0.3.6. PR [#58](https://github.com/linyqh/NarratoAI/pull/58) by [@linyqh](https://github.com/linyqh).
|
||||
* 0.3.4 修改各种bug. PR [#49](https://github.com/linyqh/NarratoAI/pull/49) by [@linyqh](https://github.com/linyqh).
|
||||
@ -1,178 +0,0 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from typing import Dict, Any
|
||||
|
||||
class VideoPipeline:
|
||||
def __init__(self, base_url: str = "http://127.0.0.1:8080"):
|
||||
self.base_url = base_url
|
||||
|
||||
def download_video(self, url: str, resolution: str = "1080p",
|
||||
output_format: str = "mp4", rename: str = None) -> Dict[str, Any]:
|
||||
"""下载视频的第一步"""
|
||||
endpoint = f"{self.base_url}/api/v2/youtube/download"
|
||||
payload = {
|
||||
"url": url,
|
||||
"resolution": resolution,
|
||||
"output_format": output_format,
|
||||
"rename": rename or time.strftime("%Y-%m-%d")
|
||||
}
|
||||
|
||||
response = requests.post(endpoint, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def generate_script(self, video_path: str, skip_seconds: int = 0,
|
||||
threshold: int = 30, vision_batch_size: int = 10,
|
||||
vision_llm_provider: str = "gemini") -> Dict[str, Any]:
|
||||
"""生成脚本的第二步"""
|
||||
endpoint = f"{self.base_url}/api/v2/scripts/generate"
|
||||
payload = {
|
||||
"video_path": video_path,
|
||||
"skip_seconds": skip_seconds,
|
||||
"threshold": threshold,
|
||||
"vision_batch_size": vision_batch_size,
|
||||
"vision_llm_provider": vision_llm_provider
|
||||
}
|
||||
|
||||
response = requests.post(endpoint, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def crop_video(self, video_path: str, script: list) -> Dict[str, Any]:
|
||||
"""剪辑视频的第三步"""
|
||||
endpoint = f"{self.base_url}/api/v2/scripts/crop"
|
||||
payload = {
|
||||
"video_origin_path": video_path,
|
||||
"video_script": script
|
||||
}
|
||||
|
||||
response = requests.post(endpoint, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def generate_final_video(self, task_id: str, video_path: str,
|
||||
script_path: str, script: list, subclip_videos: Dict[str, str], voice_name: str) -> Dict[str, Any]:
|
||||
"""生成最终视频的第四步"""
|
||||
endpoint = f"{self.base_url}/api/v2/scripts/start-subclip"
|
||||
|
||||
request_data = {
|
||||
"video_clip_json": script,
|
||||
"video_clip_json_path": script_path,
|
||||
"video_origin_path": video_path,
|
||||
"video_aspect": "16:9",
|
||||
"video_language": "zh-CN",
|
||||
"voice_name": voice_name,
|
||||
"voice_volume": 1,
|
||||
"voice_rate": 1.2,
|
||||
"voice_pitch": 1,
|
||||
"bgm_name": "random",
|
||||
"bgm_type": "random",
|
||||
"bgm_file": "",
|
||||
"bgm_volume": 0.3,
|
||||
"subtitle_enabled": True,
|
||||
"subtitle_position": "bottom",
|
||||
"font_name": "STHeitiMedium.ttc",
|
||||
"text_fore_color": "#FFFFFF",
|
||||
"text_background_color": "transparent",
|
||||
"font_size": 75,
|
||||
"stroke_color": "#000000",
|
||||
"stroke_width": 1.5,
|
||||
"custom_position": 70,
|
||||
"n_threads": 8
|
||||
}
|
||||
|
||||
payload = {
|
||||
"request": request_data,
|
||||
"subclip_videos": subclip_videos
|
||||
}
|
||||
|
||||
params = {"task_id": task_id}
|
||||
response = requests.post(endpoint, params=params, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def save_script_to_json(self, script: list, script_path: str) -> str:
|
||||
"""保存脚本到json文件"""
|
||||
try:
|
||||
with open(script_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(script, f, ensure_ascii=False, indent=2)
|
||||
print(f"脚本已保存到: {script_path}")
|
||||
return script_path
|
||||
except Exception as e:
|
||||
print(f"保存脚本失败: {str(e)}")
|
||||
raise
|
||||
|
||||
def run_pipeline(self, task_id: str, script_name: str, youtube_url: str, video_name: str="null", skip_seconds: int = 0, threshold: int = 30, vision_batch_size: int = 10, vision_llm_provider: str = "gemini", voice_name: str = "zh-CN-YunjianNeural") -> Dict[str, Any]:
|
||||
"""运行完整的pipeline"""
|
||||
try:
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
video_path = os.path.join(current_path, "resource", "videos", f"{video_name}.mp4")
|
||||
# 判断视频是否存在
|
||||
if not os.path.exists(video_path):
|
||||
# 1. 下载视频
|
||||
print(f"视频不存在, 开始下载视频: {video_path}")
|
||||
download_result = self.download_video(url=youtube_url, resolution="1080p", output_format="mp4", rename=video_name)
|
||||
video_path = download_result["output_path"]
|
||||
else:
|
||||
print(f"视频已存在: {video_path}")
|
||||
|
||||
# 2. 判断script_name是否存在
|
||||
# 2.1.1 拼接脚本路径 NarratoAI/resource/scripts
|
||||
script_path = os.path.join(current_path, "resource", "scripts", script_name)
|
||||
if os.path.exists(script_path):
|
||||
script = json.load(open(script_path, "r", encoding="utf-8"))
|
||||
else:
|
||||
# 2.1.2 生成脚本
|
||||
print("开始生成脚本...")
|
||||
script_result = self.generate_script(video_path=video_path, skip_seconds=skip_seconds, threshold=threshold, vision_batch_size=vision_batch_size, vision_llm_provider=vision_llm_provider)
|
||||
script = script_result["script"]
|
||||
|
||||
# 2.2 保存脚本到json文件
|
||||
print("保存脚本到json文件...")
|
||||
self.save_script_to_json(script=script, script_path=script_path)
|
||||
|
||||
# 3. 剪辑视频
|
||||
print("开始剪辑视频...")
|
||||
crop_result = self.crop_video(video_path=video_path, script=script)
|
||||
subclip_videos = crop_result["subclip_videos"]
|
||||
|
||||
# 4. 生成最终视频
|
||||
print("开始生成最终视频...")
|
||||
self.generate_final_video(
|
||||
task_id=task_id,
|
||||
video_path=video_path,
|
||||
script_path=script_path,
|
||||
script=script,
|
||||
subclip_videos=subclip_videos,
|
||||
voice_name=voice_name
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "等待异步生成视频",
|
||||
"path": os.path.join(current_path, "storage", "tasks", task_id)
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
pipeline = VideoPipeline()
|
||||
result = pipeline.run_pipeline(
|
||||
task_id="test_111901",
|
||||
script_name="test.json",
|
||||
youtube_url="https://www.youtube.com/watch?v=vLJ7Yed6FQ4",
|
||||
video_name="2024-11-19-01",
|
||||
skip_seconds=50,
|
||||
threshold=35,
|
||||
vision_batch_size=10,
|
||||
vision_llm_provider="gemini",
|
||||
voice_name="zh-CN-YunjianNeural",
|
||||
)
|
||||
print(result)
|
||||
Loading…
x
Reference in New Issue
Block a user