mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-10 18:02:51 +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
|
||||
tomli~=2.2.1
|
||||
pydub==0.25.1
|
||||
pysrt==1.1.2
|
||||
|
||||
openai~=1.77.0
|
||||
google-generativeai>=0.8.5
|
||||
|
||||
@ -1,20 +1,13 @@
|
||||
import os
|
||||
import time
|
||||
import math
|
||||
import sys
|
||||
import tempfile
|
||||
import traceback
|
||||
import shutil
|
||||
|
||||
import streamlit as st
|
||||
from loguru import logger
|
||||
from typing import List, Dict, Tuple
|
||||
from typing import List, Dict
|
||||
from dataclasses import dataclass
|
||||
from streamlit.runtime.uploaded_file_manager import UploadedFile
|
||||
|
||||
from webui.utils.merge_video import merge_videos_and_subtitles
|
||||
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")
|
||||
@ -169,38 +162,38 @@ def render_merge_settings(tr):
|
||||
else:
|
||||
st.warning(tr("Missing Subtitle"))
|
||||
# 如果有视频但没有字幕,显示一键转录按钮
|
||||
if os.path.exists(video_path):
|
||||
if st.button(tr("One-Click Transcribe"), key=f"transcribe_{base_name}"):
|
||||
with st.spinner(tr("Transcribing...")):
|
||||
try:
|
||||
# 生成字幕文件
|
||||
result = extract_audio_and_create_subtitle(video_path, subtitle_path)
|
||||
if result:
|
||||
# 读取生成的字幕文件内容并显示预览
|
||||
with open(subtitle_path, 'r', encoding='utf-8') as f:
|
||||
subtitle_content = f.read()
|
||||
st.markdown(tr("Subtitle Preview"))
|
||||
st.text_area(
|
||||
"Subtitle Content",
|
||||
value=subtitle_content,
|
||||
height=150,
|
||||
label_visibility="collapsed",
|
||||
key=f"subtitle_preview_transcribed_{base_name}"
|
||||
)
|
||||
st.success(tr("Transcription Complete!"))
|
||||
# 更新pair的字幕文件路径
|
||||
pair.subtitle_file = subtitle_path
|
||||
else:
|
||||
st.error(tr("Transcription Failed. Please try again."))
|
||||
except Exception as e:
|
||||
error_message = str(e)
|
||||
logger.error(traceback.format_exc())
|
||||
if "rate limit exceeded" in error_message.lower():
|
||||
st.error(tr("API rate limit exceeded. Please wait about an hour and try again."))
|
||||
elif "resource_exhausted" in error_message.lower():
|
||||
st.error(tr("Resources exhausted. Please try again later."))
|
||||
else:
|
||||
st.error(f"{tr('Transcription Failed')}: {str(e)}")
|
||||
# if os.path.exists(video_path):
|
||||
# if st.button(tr("One-Click Transcribe"), key=f"transcribe_{base_name}"):
|
||||
# with st.spinner(tr("Transcribing...")):
|
||||
# try:
|
||||
# # 生成字幕文件
|
||||
# result = extract_audio_and_create_subtitle(video_path, subtitle_path)
|
||||
# if result:
|
||||
# # 读取生成的字幕文件内容并显示预览
|
||||
# with open(subtitle_path, 'r', encoding='utf-8') as f:
|
||||
# subtitle_content = f.read()
|
||||
# st.markdown(tr("Subtitle Preview"))
|
||||
# st.text_area(
|
||||
# "Subtitle Content",
|
||||
# value=subtitle_content,
|
||||
# height=150,
|
||||
# label_visibility="collapsed",
|
||||
# key=f"subtitle_preview_transcribed_{base_name}"
|
||||
# )
|
||||
# st.success(tr("Transcription Complete!"))
|
||||
# # 更新pair的字幕文件路径
|
||||
# pair.subtitle_file = subtitle_path
|
||||
# else:
|
||||
# st.error(tr("Transcription Failed. Please try again."))
|
||||
# except Exception as e:
|
||||
# error_message = str(e)
|
||||
# logger.error(traceback.format_exc())
|
||||
# if "rate limit exceeded" in error_message.lower():
|
||||
# st.error(tr("API rate limit exceeded. Please wait about an hour and try again."))
|
||||
# elif "resource_exhausted" in error_message.lower():
|
||||
# st.error(tr("Resources exhausted. Please try again later."))
|
||||
# else:
|
||||
# st.error(f"{tr('Transcription Failed')}: {str(e)}")
|
||||
|
||||
# 排序输入框
|
||||
order = st.number_input(
|
||||
|
||||
@ -143,7 +143,7 @@
|
||||
"Merge All Files": "合并所有文件",
|
||||
"Merge Function Not Implemented": "合并功能待实现",
|
||||
"No Matched Pairs Found": "未找到匹配的文件对",
|
||||
"Missing Subtitle": "缺少对应的字幕文件",
|
||||
"Missing Subtitle": "缺少对应的字幕文件, 请使用其他软件完成字幕转录,比如剪映等",
|
||||
"Missing Video": "缺少对应的视频文件",
|
||||
"All Uploaded Files": "所有上传的文件",
|
||||
"Order": "排序序号",
|
||||
|
||||
@ -150,7 +150,7 @@ def chekc_video_config(video_params):
|
||||
session.mount("https://", adapter)
|
||||
try:
|
||||
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,
|
||||
json=video_params,
|
||||
timeout=30,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
"""
|
||||
合并视频和字幕文件
|
||||
"""
|
||||
from moviepy import VideoFileClip, concatenate_videoclips
|
||||
# import pysrt
|
||||
import os
|
||||
import pysrt
|
||||
from moviepy import VideoFileClip, concatenate_videoclips
|
||||
|
||||
|
||||
def get_video_duration(video_path):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user