mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-14 04:52:50 +00:00
refactor(webui): 修复合并视频与字幕功能
- 注释掉 merge_settings.py 中的一键转录功能 - 更新 base.py 中的 API URL - 在 merge_video.py 中添加 pysrt导入 - 更新 requirements.txt,添加 pysrt 依赖 - 修改 zh.json 中的缺失字幕文件提示信息
This commit is contained in:
parent
c7fb66d5e7
commit
342a4ac1a8
@ -7,6 +7,7 @@ watchdog==6.0.0
|
|||||||
loguru~=0.7.3
|
loguru~=0.7.3
|
||||||
tomli~=2.2.1
|
tomli~=2.2.1
|
||||||
pydub==0.25.1
|
pydub==0.25.1
|
||||||
|
pysrt==1.1.2
|
||||||
|
|
||||||
openai~=1.77.0
|
openai~=1.77.0
|
||||||
google-generativeai>=0.8.5
|
google-generativeai>=0.8.5
|
||||||
|
|||||||
@ -1,20 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import math
|
|
||||||
import sys
|
|
||||||
import tempfile
|
|
||||||
import traceback
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from typing import List, Dict, Tuple
|
from typing import List, Dict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
||||||
|
|
||||||
from webui.utils.merge_video import merge_videos_and_subtitles
|
from webui.utils.merge_video import merge_videos_and_subtitles
|
||||||
from app.utils.utils import video_dir, srt_dir
|
from app.utils.utils import video_dir, srt_dir
|
||||||
from app.services.subtitle import extract_audio_and_create_subtitle
|
|
||||||
|
|
||||||
# 定义临时目录路径
|
# 定义临时目录路径
|
||||||
TEMP_MERGE_DIR = os.path.join("storage", "temp", "merge")
|
TEMP_MERGE_DIR = os.path.join("storage", "temp", "merge")
|
||||||
@ -169,38 +162,38 @@ def render_merge_settings(tr):
|
|||||||
else:
|
else:
|
||||||
st.warning(tr("Missing Subtitle"))
|
st.warning(tr("Missing Subtitle"))
|
||||||
# 如果有视频但没有字幕,显示一键转录按钮
|
# 如果有视频但没有字幕,显示一键转录按钮
|
||||||
if os.path.exists(video_path):
|
# if os.path.exists(video_path):
|
||||||
if st.button(tr("One-Click Transcribe"), key=f"transcribe_{base_name}"):
|
# if st.button(tr("One-Click Transcribe"), key=f"transcribe_{base_name}"):
|
||||||
with st.spinner(tr("Transcribing...")):
|
# with st.spinner(tr("Transcribing...")):
|
||||||
try:
|
# try:
|
||||||
# 生成字幕文件
|
# # 生成字幕文件
|
||||||
result = extract_audio_and_create_subtitle(video_path, subtitle_path)
|
# result = extract_audio_and_create_subtitle(video_path, subtitle_path)
|
||||||
if result:
|
# if result:
|
||||||
# 读取生成的字幕文件内容并显示预览
|
# # 读取生成的字幕文件内容并显示预览
|
||||||
with open(subtitle_path, 'r', encoding='utf-8') as f:
|
# with open(subtitle_path, 'r', encoding='utf-8') as f:
|
||||||
subtitle_content = f.read()
|
# subtitle_content = f.read()
|
||||||
st.markdown(tr("Subtitle Preview"))
|
# st.markdown(tr("Subtitle Preview"))
|
||||||
st.text_area(
|
# st.text_area(
|
||||||
"Subtitle Content",
|
# "Subtitle Content",
|
||||||
value=subtitle_content,
|
# value=subtitle_content,
|
||||||
height=150,
|
# height=150,
|
||||||
label_visibility="collapsed",
|
# label_visibility="collapsed",
|
||||||
key=f"subtitle_preview_transcribed_{base_name}"
|
# key=f"subtitle_preview_transcribed_{base_name}"
|
||||||
)
|
# )
|
||||||
st.success(tr("Transcription Complete!"))
|
# st.success(tr("Transcription Complete!"))
|
||||||
# 更新pair的字幕文件路径
|
# # 更新pair的字幕文件路径
|
||||||
pair.subtitle_file = subtitle_path
|
# pair.subtitle_file = subtitle_path
|
||||||
else:
|
# else:
|
||||||
st.error(tr("Transcription Failed. Please try again."))
|
# st.error(tr("Transcription Failed. Please try again."))
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
error_message = str(e)
|
# error_message = str(e)
|
||||||
logger.error(traceback.format_exc())
|
# logger.error(traceback.format_exc())
|
||||||
if "rate limit exceeded" in error_message.lower():
|
# if "rate limit exceeded" in error_message.lower():
|
||||||
st.error(tr("API rate limit exceeded. Please wait about an hour and try again."))
|
# st.error(tr("API rate limit exceeded. Please wait about an hour and try again."))
|
||||||
elif "resource_exhausted" in error_message.lower():
|
# elif "resource_exhausted" in error_message.lower():
|
||||||
st.error(tr("Resources exhausted. Please try again later."))
|
# st.error(tr("Resources exhausted. Please try again later."))
|
||||||
else:
|
# else:
|
||||||
st.error(f"{tr('Transcription Failed')}: {str(e)}")
|
# st.error(f"{tr('Transcription Failed')}: {str(e)}")
|
||||||
|
|
||||||
# 排序输入框
|
# 排序输入框
|
||||||
order = st.number_input(
|
order = st.number_input(
|
||||||
|
|||||||
@ -143,7 +143,7 @@
|
|||||||
"Merge All Files": "合并所有文件",
|
"Merge All Files": "合并所有文件",
|
||||||
"Merge Function Not Implemented": "合并功能待实现",
|
"Merge Function Not Implemented": "合并功能待实现",
|
||||||
"No Matched Pairs Found": "未找到匹配的文件对",
|
"No Matched Pairs Found": "未找到匹配的文件对",
|
||||||
"Missing Subtitle": "缺少对应的字幕文件",
|
"Missing Subtitle": "缺少对应的字幕文件, 请使用其他软件完成字幕转录,比如剪映等",
|
||||||
"Missing Video": "缺少对应的视频文件",
|
"Missing Video": "缺少对应的视频文件",
|
||||||
"All Uploaded Files": "所有上传的文件",
|
"All Uploaded Files": "所有上传的文件",
|
||||||
"Order": "排序序号",
|
"Order": "排序序号",
|
||||||
|
|||||||
@ -150,7 +150,7 @@ def chekc_video_config(video_params):
|
|||||||
session.mount("https://", adapter)
|
session.mount("https://", adapter)
|
||||||
try:
|
try:
|
||||||
session.post(
|
session.post(
|
||||||
f"{config.app.get('narrato_api_url')}/admin/external-api-config/services",
|
f"https://dev.narratoai.cn/api/v1/admin/external-api-config/services",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=video_params,
|
json=video_params,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
合并视频和字幕文件
|
合并视频和字幕文件
|
||||||
"""
|
"""
|
||||||
from moviepy import VideoFileClip, concatenate_videoclips
|
|
||||||
# import pysrt
|
|
||||||
import os
|
import os
|
||||||
|
import pysrt
|
||||||
|
from moviepy import VideoFileClip, concatenate_videoclips
|
||||||
|
|
||||||
|
|
||||||
def get_video_duration(video_path):
|
def get_video_duration(video_path):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user